﻿'use strict';
if (sytdapp.platform.isValid()) {
    alert = function (msg, time) {
        //var _oldTime = time;
        //var compMSG = "(time || undefined) === undefined：" + (time || undefined) === undefined;
        //compMSG += 'typeof (time) !== "number"' + typeof (time) !== "number";
        if ((time || undefined) === undefined || typeof (time) !== "number") {
            time = 3;
        }
        MessageApp.doAlert(msg, time);
    };
}
function dealErrorMessage($scope, data) {
    var r = "";
    if (typeof (data) == "undefined") {
        r = "undefined";
    } else if (typeof (data) == "object") {
        var s = "";
        for (var a in data) {
            if (s == "") {
                s += "" + a;
            } else {
                s += "\r\n" + a;
            }
        }
        r = s;
    } else {
        r = data;
    }
    $scope.errorMesssage = r;
    return r;
}
var app = angular.module("zjwapp", ["ngRoute", "ngResource"], function ($httpProvider) {
    // Use x-www-form-urlencoded Content-Type
    $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
    $httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded';

    //var _header = { "token": "test" };
    //if (sytdapp.LoggedUser.islogged()) {
    //    var cid = sytdapp.LoggedUser.get();
    //    _header.customerid = cid;//添加Head
    //    $httpProvider.defaults.headers.post["customerid"] = cid;
    //}
    //$httpProvider.defaults.headers.get = _header;

    // Override $http service's default transformRequest
    $httpProvider.defaults.transformRequest = [function (data) {
        /**
         * The workhorse; converts an object to x-www-form-urlencoded serialization.
         * @param {Object} obj
         * @return {String}
         */
        var param = function (obj) {
            var query = '';
            var name, value, fullSubName, subName, subValue, innerObj, i;

            for (name in obj) {
                value = obj[name];

                if (value instanceof Array) {
                    for (i = 0; i < value.length; ++i) {
                        subValue = value[i];
                        fullSubName = name + '[' + i + ']';
                        innerObj = {
                        };
                        innerObj[fullSubName] = subValue;
                        query += param(innerObj) + '&';
                    }
                }
                else if (value instanceof Object) {
                    for (subName in value) {
                        subValue = value[subName];
                        fullSubName = name + '[' + subName + ']';
                        innerObj = {
                        };
                        innerObj[fullSubName] = subValue;
                        query += param(innerObj) + '&';
                    }
                }
                else if (value !== undefined && value !== null) {
                    query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
                }
            }

            return query.length ? query.substr(0, query.length - 1) : query;
        };

        return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
    }];
});
app.config(["$routeProvider", function routerConfig($routeProvider) {
    $routeProvider
    .when("/", { controller: "IndexController", templateUrl: "app/view/index/index2.html" })
    //新闻
    .when("/newslist", { controller: "NewsListController", templateUrl: "app/view/news/newslist.html" })
    .when("/newsdetail/:id", { controller: "NewsDetailController", templateUrl: "app/view/news/newsdetail.html" })
    //公告
    .when("/noticelist", { controller: "NoticeListController", templateUrl: "app/view/notice/noticelist.html" })
    .when("/noticedetail/:id", { controller: "NoticeDetailController", templateUrl: "app/view/notice/noticedetail.html" })
    //装修备案
    .when("/deco", { controller: "DecoController", templateUrl: "app/view/deco/list.html", needLogin: true })
    .when("/decoapply", { controller: "DecoApplyController", templateUrl: "app/view/deco/apply.html", needLogin: true })
    .when("/apointlist/:area", { controller: "APointListController", templateUrl: "app/view/deco/apointlist.html", needLogin: true })
    .when("/applypoint/:point", { controller: "ApplyPointController", templateUrl: "app/view/deco/applypoint.html", needLogin: true })
    .when("/decopoint/:point/:baidu", { controller: "DecoPointController", templateUrl: "app/view/deco/decopoint.html", needLogin: true })
    .when("/pointmap/:point", { controller: "PointMapController", templateUrl: "app/view/deco/pointmap.html", needLogin: true })
    .when("/decorate", { controller: "DecoRateController", templateUrl: "app/view/deco/decorate.html", needLogin: true })
    //房屋巡查
    .when("/patrol", { controller: "PatrolController", templateUrl: "app/view/patrol/list.html", needLogin: true })
    .when("/repoint", { controller: "RePointController", templateUrl: "app/view/patrol/repoint.html", needLogin: true })
    .when("/repointmap/:id", { controller: "RePointMapController", templateUrl: "app/view/patrol/repointmap.html", needLogin: true })
    .when("/decolog", { controller: "DecoLogController", templateUrl: "app/view/patrol/decolog.html", needLogin: true })
    .when("/decologd/:id", { controller: "DecoLogDController", templateUrl: "app/view/patrol/decologd.html", needLogin: true })
    .when("/patroltask", { controller: "PatrolTaskController", templateUrl: "app/view/patrol/patrollist.html", needLogin: true })
    .when("/patrolnew", { controller: "PatrolNewController", templateUrl: "app/view/patrol/patrolnew.html", needLogin: true })
    .when("/patroltaskd/:id", { controller: "PatrolTaskDController", templateUrl: "app/view/patrol/patrollog.html", needLogin: true })
    .when("/rehouse", { controller: "ReHouseController", templateUrl: "app/view/patrol/rehouse.html", needLogin: true })
    //装修巡查
    .when("/padelog", { controller: "PadelogController", templateUrl: "app/view/patrol/padelog.html", needLogin: true })
    .when("/padelogd/:id", { controller: "PadelogDController", templateUrl: "app/view/patrol/padelogd.html", needLogin: true })
    //公积金查询
    .when("/gjjquery/:type/:name", { controller: "GJJQUERYController", templateUrl: "app/view/tool/gjjquery.html", needLogin: true })
    .when("/gjjcx", { controller: "GJJCXController", templateUrl: "app/view/tool/gjjcx.html", needLogin: true })
    //外链查询
    .when("/wywxjj", { controller: "WYWXJJController", templateUrl: "app/view/guide/wywxjj.html" })
    //房屋征收
    .when("/fwzsgk", { controller: "FWZSController", templateUrl: "app/view/fwzs/fwzs.html" })
        .when("/fxmgk", { controller: "FXMGKController", templateUrl: "app/view/fwzs/xmgk.html" })
        .when("/fzsjd", { controller: "FZSJDController", templateUrl: "app/view/fwzs/zsjd.html" })
        .when("/fxmgg", { controller: "FXMGGController", templateUrl: "app/view/fwzs/xmgg.html" })
        .when("/fbszn", { controller: "FBSZNController", templateUrl: "app/view/fwzs/bszn.html" })
        .when("/fzcfg", { controller: "FZCFGController", templateUrl: "app/view/fwzs/zcfg.html" })
        .when("/fdcjg", { controller: "FDCJGController", templateUrl: "app/view/fwzs/dcjg.html" })
        .when("/fpgjg", { controller: "FPGJGController", templateUrl: "app/view/fwzs/pgjg.html" })
        .when("/fbcjg", { controller: "FBCJGController", templateUrl: "app/view/fwzs/bcjg.html" })
    .when("/xzspjg", { controller: "XZSPJGController", templateUrl: "app/view/guide/xzspjg.html" })
    .when("/xndt", { controller: "XNDTController", templateUrl: "app/view/guide/xndt.html" })
    //我有话说
    .when("/wyhs", { controller: "WYHSController", templateUrl: "app/view/person/wyhs.html" })
    //个人中心
    .when("/center", { controller: "CenterController", templateUrl: "app/view/center/index.html", needLogin: true })//个人中心
    .when("/uptmk", { controller: "UptMKController", templateUrl: "app/view/center/uptmk.html", needLogin: true })
    .when("/uptpwd", { controller: "UptPwdController", templateUrl: "app/view/center/uptpwd.html", needLogin: true })
    .when("/uptname", { controller: "UptNameController", templateUrl: "app/view/center/uptname.html", needLogin: true })
    .when("/uptphone", { controller: "UptPhoneController", templateUrl: "app/view/center/uptphone.html", needLogin: true })
    .when("/morder", { controller: "MOrderController", templateUrl: "app/view/center/morder.html", needLogin: true })
    .when("/message", { controller: "MessageController", templateUrl: "app/view/center/message.html", needLogin: true })
    //登录注册
    .when("/login", { controller: "LoginController", templateUrl: "app/view/login/login.html" })
    .when("/register", { controller: "RegisterController", templateUrl: "app/view/login/register.html" })
    .when("/forgetpwd", { controller: "ForgetPwdController", templateUrl: "app/view/login/forgetpwd.html" })
    //计算工具
    .when("/principal", { controller: "PrincipalController", templateUrl: "app/view/tool/principal.html" })
    .when("/interest", { controller: "InterestController", templateUrl: "app/view/tool/interest.html" })
    .when("/housingfund", { controller: "HousingFundController", templateUrl: "app/view/tool/housingfund.html" })
    .when("/rate", { controller: "RateController", templateUrl: "app/view/tool/rate.html" })
    //企业资质
    .when("/enterprice", { controller: "EnterpriceLController", templateUrl: "app/view/company/list.html" })
    .when("/enterpriced/:id", { controller: "EnterpriceDController", templateUrl: "app/view/company/detail.html" })
    //企业信用
    .when("/enterpricecredit", { controller: "EnterpriceCreditLController", templateUrl: "app/view/companycredit/list.html" })
    //工程项目
    .when("/project", { controller: "ProjectLController", templateUrl: "app/view/project/list.html" })
    .when("/projectd/:id", { controller: "ProjectDController", templateUrl: "app/view/project/detail.html" })
    //楼盘
    .when("/house", { controller: "HouseLController", templateUrl: "app/view/house/list.html" })
    .when("/housed/:id", { controller: "HouseDController", templateUrl: "app/view/house/detail.html" })
    //办事指南
    .when("/guide", { controller: "GuideController", templateUrl: "app/view/guide/work.html" })
    .when("/guidedetail/:id", { controller: "GuideDController", templateUrl: "app/view/guide/workdetail.html" })
    //鉴定列表
    .when("/org", { controller: "OrgController", templateUrl: "app/view/pubhousesafe/org.html" })
    .when("/orgd/:id", { controller: "OrgDController", templateUrl: "app/view/pubhousesafe/orgd.html" })
    //危房列表
    .when("/dhouse", { controller: "DHouseListController", templateUrl: "app/view/pubhousesafe/dhouselist.html" })
    .when("/dhoused/:id", { controller: "DHouseDController", templateUrl: "app/view/pubhousesafe/dhouse.html" })
    //专题
    .when("/special", { controller: "SpecialkController", templateUrl: "app/view/special/index.html" })
    .when("/speciall/:id", { controller: "SpeciallController", templateUrl: "app/view/special/list.html" })
    .when("/speciald/:id", { controller: "SpecialdController", templateUrl: "app/view/special/detail.html" })
    //绑定宽易帐号
    .when("/bindky", { controller: "BindKYController", templateUrl: "app/view/login/bindky.html" })
    .when("/myfav", { controller: "MyFavController", templateUrl: "app/view/center/myfav.html", needLogin: true })
    .when("/myitem", { controller: "MyItemController", templateUrl: "app/view/center/myitem.html", needLogin: true })
    .when("/ceshi", { controller: "CSController", templateUrl: "app/view/ceshi.html" })
    .otherwise({
        redirectTo: "/"
    });
}])
    .run(["$rootScope", "$location", "$http", "zjwappFactory", function ($rootScope, $location, $http, fac) {
        $rootScope.$on("$routeChangeStart", function (event, next, current) {
            var platformIsValid = sytdapp.platform.isValid();//平台是否有效

            //var back = function () {
            //    fac.trackRecord.back($location);
            //}
            //$rootScope.back = back;

            //if (sytdapp.platform.android) {//安卓添加
            //    document.addEventListener("backbutton", function () {
            //        back();
            //    }, false);
            //}

            var fn_dg = function () {
                var path = next.$$route.originalPath + ""; //$location.$$path
                for (var item in next.pathParams) {
                    var _val = next.pathParams[item];
                    var _item = ":" + item;
                    path = path.replace(_item, _val);
                }
                fac.trackRecord.record(next.controller, path, current == null, _needlogin, _islogged);//记录每次切换的路径

                var _islogged = sytdapp.LoggedUser.islogged();
                var _needlogin = next.needLogin || false;

                if (_needlogin) {//需要验证登录的
                    if (!_islogged) {
                        fac.redirect2login();
                    }
                }
                if (_islogged) {
                    var cid = sytdapp.LoggedUser.get();
                    $http.defaults.headers.common.customerid = cid;
                }
            }
            //document.addEventListener("deviceready", function () {
            //    //MessageApp.getDeviceMessage(function (p) {
            //    //    alert(p);
            //    //}, function () {

            //    //})
            //});
            try {
                if (platformIsValid) {
                    var __userInfo = sytdapp.Native_Util.getURLAttribute("ZJWAPP_COOKIE_USERINFO");
                    if ((__userInfo || null) !== null) {
                        __userInfo = decodeURIComponent(__userInfo);
                        __userInfo = eval("(" + __userInfo + ")");
                    }
                    if ((__userInfo || null) === null || (__userInfo.ID || undefined) === undefined) {
                        //sytdapp.LoggedUser.clear();
                    } else {
                        sytdapp.LoggedUser.set(__userInfo.ID);
                    }
                }
                fn_dg();
            } catch (e) {
                //alert("获取原生用户信息出错！");
            }
            /*****************************end 以下信息改用获取cookie的值**********************************************/
        });
    }]);


//重新加载JS
function f_loadscript(path) {
    var loadscript = {
        delay: function ($q) {
            var delay = $q.defer(),
            load = function () {
                $.getScript(path, function () {
                    delay.resolve();
                });
            };
            load();
            return delay.promise;
        }
    }
    return loadscript;
}
Array.prototype.remove = function (dx) {
    if (isNaN(dx) || dx > this.length) {
        return false;
    }
    for (var i = 0, n = 0; i < this.length; i++) {
        if (this[i] != this[dx]) {
            this[n++] = this[i]
        }
    }
    this.length -= 1
}
//首页
app.controller("IndexController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    //fac.accessStatistics("#/");
    var first = window.localStorage.getItem("firstlogin");
    if (first == "0") {
        window.localStorage.setItem("firstlogin", "1")
    } else {

    }
    $scope.weather = {
        Img: null, Pm25: "获取中", Temperature: "0", Weather: "获取中"
    };
    $scope.trafjam = {
        Describe: "获取中", Value: "获取中"
    };
    $scope.active = [];
    $scope.news = [{
        "T_NEWS": { "TITLE": "获取中" }, "isimg": false
    }]

    fac.get("天气", "weather/GetWeather", function (data) {
        $scope.weather = data;
    });
    fac.get("拥堵指数", "weather/GetTrafficJam", function (data) {
        $scope.trafjam = data;
    });
    fac.get("活动", "Activity/Get", function (data) {
        if (data == null || data == undefined || data.length == 0) {
            $(".index-banner").hide();
            $scope.active = [];
        } else {
            $(".index-banner").show();
            $scope.active = data;
        }
    });

    fac.get("热门", "News/GetHot", function (data) {
        for (var i = 0; i < data.length; i++) {
            data[i].isimg = data[i].img != null;
        }
        $scope.news = data;
    });

    $scope.detail = function (id) {
        $location.path("/newsdetail/" + id);
    }

    if (sytdapp.LoggedUser.islogged()) {
        fac.get("获取用户订阅", "Subscribe/GetCustomerSubscribe", function (data) {
            var order1 = new Array();
            var order2 = new Array();
            for (var i = 0; i < data.length; i++) {
                if (i < 3) {
                    order1.push(data[i]);
                } else {
                    order2.push(data[i]);
                }
            }
            $scope.dylist1 = order1;
            $scope.dylist2 = order2;
        })
    } else {
        fac.get("获取默认订阅", "Subscribe/GetDefault", function (data) {
            $scope.dylist1 = data;
            $scope.dylist2 = null;
        })
    }
    $scope.Done = function () {
        setTimeout(function () {
            var tt_height = $(window).height() - 169;
            var ttt_height = $(".t_dai .handle").height();
            if (ttt_height > tt_height) {
                var ttt_height2 = $(".t_dai .handle").height() + 161;
                $(".t_dai .handle").height(ttt_height2);
                window.localStorage.setItem("opacity_x", 2)
            } else {
                $(".t_dai .handle").height(ttt_height);
                $(".t_dai").height(ttt_height - 1);
                window.localStorage.setItem("opacity_x", 0.02)
            }
            new Dragdealer('top-n', {
                y: 0,
                vertical: true,
                speed: 0.2,
                loose: true,
                animationCallback: function (x, y) {
                    $("#top-no").html(y);
                    var opacity_x = window.localStorage.getItem("opacity_x")
                    $(".svg").css({
                        opacity: -y * opacity_x
                    });
                },
                dragStopCallback: function () {
                    var yy = -$("#top-no").html();
                    if (yy >= 0.15) {
                        $(".t_dai").css({
                            "z-index": "8", "visibility": "hidden"
                        });
                        $(".top-m").css({
                            "z-index": "9", "visibility": "visible"
                        });
                        topm.setValue(0, 1)
                    }
                }
            });
            var topm = new Dragdealer('top-m', {
                y: 1,
                steps: 2,
                speed: 0.2,
                vertical: true,
                loose: true,
                animationCallback: function (x, y) {
                    if (y >= 1) {
                        $("#top-mo").html(y)
                    }
                    $(".index-news").height(y * 80);
                    $(".svg2").css({
                        opacity: (y - 1) * 1
                    });
                },
                dragStopCallback: function () {
                    var arr = this.getStep();
                    var yy = $("#top-mo").html();
                    if (arr[1] == 1) {
                        $(".top-m").css({
                            "z-index": "8", "visibility": "hidden"
                        });
                        $(".t_dai").css({
                            "z-index": "9", "visibility": "visible"
                        });
                    }
                    else if (yy >= 1.2) {
                        line_down()
                    }
                }
            })
            new Dragdealer('dragdealer_n', {
                vertical: true
            })
        }, 500);
    }
    $scope.tiaozhuan = function (path, name) {
        if (path[0] == "#") {
            var path2 = path.replace("#", "");
            $location.path(path2);
        } else {
            window.location = "ifr.html?u=" + escape(path) + "&t=" + escape(name);
        }
    }
}]);
//新闻列表
app.controller("NewsListController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {

    //$scope.back = function () {
    //    $location.path("/");
    //}
    fac.accessStatistics("#/newslist");
    var newstype = window.localStorage.getItem("newstype");
    window.localStorage.setItem("typepage", 0);
    window.localStorage.setItem("page", 1);
    if (newstype == undefined || newstype == null) {
        fac.get("新闻类型", "News/GetAllNewsType", function (data) {
            $scope.newstype = data
            $scope.typeid = data[0].ID;
            window.localStorage.setItem("newstypeid", 0)
            window.localStorage.setItem("newsid", data[0].ID)
            window.localStorage.setItem("title", "")
            $scope.page = 1;
            $scope.rows = 10;
            fac.get("获取新闻", "News/GetNewsAll?title=&typeid=" + data[0].ID + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                for (var i = 0; i < data.length; i++) {
                    if (data[i].newsbiglist.length == 0) {
                        $("#pagination" + i).hide();
                    }
                    for (var j = 0; j < data[i].newslist.length; j++) {
                        if (data[i].newslist[j].T_NEWS.SHOW_TITLE == null) {
                            data[i].newslist[j].isimg = false;
                        } else {
                            data[i].newslist[j].isimg = true;
                            //data[i].newslist[j].T_NEWS.SHOW_TITLE = "http://bs.nbjs.gov.cn/Upload/image/20150430/QQ%E6%88%AA%E5%9B%BE201504300845246356598038555482075177268.png"
                        }
                    }
                }
                $scope.newsall = data;
            })
        });
    } else {
        window.localStorage.removeItem("newstype");
        fac.get("新闻类型", "News/GetAllNewsType", function (data) {
            for (var i = 0; i < data.length; i++) {
                if (newstype == data[i].NAME) {
                    $scope.newstype = data
                    $scope.typeid = data[i].ID;
                    $("type0").removeClass("active");
                    $("type" + data[i].ID).addClass("active");
                    window.localStorage.setItem("newstypeid", i)
                    window.localStorage.setItem("newsid", data[i].ID)
                    window.localStorage.setItem("title", "")
                    $scope.page = 1;
                    $scope.rows = 10;
                    fac.get("获取新闻", "News/GetNewsAll?title=&typeid=" + data[i].ID + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                        for (var i = 0; i < data.length; i++) {
                            if (data[i].newsbiglist.length == 0) {
                                $("#pagination" + i).hide();
                            }
                            for (var j = 0; j < data[i].newslist.length; j++) {
                                if (data[i].newslist[j].T_NEWS.SHOW_TITLE == null) {
                                    data[i].newslist[j].isimg = false;
                                } else {
                                    data[i].newslist[j].isimg = true;
                                    //data[i].newslist[j].T_NEWS.SHOW_TITLE = "http://bs.nbjs.gov.cn/Upload/image/20150430/QQ%E6%88%AA%E5%9B%BE201504300845246356598038555482075177268.png"
                                }
                            }
                        }
                        $scope.newsall = data;
                    })
                    window.localStorage.setItem("chosedid", i);
                }
            }
        });
    }
    $scope.Done = function () {
        var newstypeid = window.localStorage.getItem("newstypeid");
        if (newstypeid == null || newstypeid == undefined) {
            $(".new-fixtop .table_a a:eq(0)").addClass("active");
        } else {
            $(".new-fixtop .table_a a:eq(" + newstypeid + ")").addClass("active");
        }
        $(".table_a a").click(function () {
            $(".table_a a.active").removeClass("active");
            $(this).addClass("active");
            new_list.slideTo($(".table_a a.active").parent().index())
        })
    }
    $scope.Done2 = function () {
        var chosedid = window.localStorage.getItem("chosedid");
        if (chosedid == null || chosedid == undefined) {
        } else {
            new_list.slideTo(chosedid)
            window.localStorage.removeItem("chosedid")
        }
    }
    //$scope.bgdone = function () {
    //    $(".xx_bg").css("height", $(document).height() - 50)
    //}
    $scope.find = function () {
        if ($scope.name == "" || $scope.name == undefined) {
            $scope.name = "";
        }
        var typepage = window.localStorage.getItem("typepage");
        for (var i = 0; i < $scope.newstype.length; i++) {
            if (typepage == i) {
                window.localStorage.setItem("newsid", $scope.newstype[i].ID);
            }
        }
        window.localStorage.setItem("title", $scope.name);
        $scope.page = 1;
        $scope.rows = 10;
        var id = window.localStorage.getItem("newsid");
        fac.get("获取新闻", "News/GetMorePage?title=" + $scope.name + "&typeid=" + id + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            for (var i = 0; i < data.length; i++) {
                if (data[i].T_NEWS.SHOW_TITLE == null) {
                    data[i].isimg = false;
                } else {
                    data[i].isimg = true;
                    //data[i].T_NEWS.SHOW_TITLE = "http://bs.nbjs.gov.cn/Upload/image/20150430/QQ%E6%88%AA%E5%9B%BE201504300845246356598038555482075177268.png"
                }
            }
            $scope.newsall[typepage].newslist = data;
        })
    }
    $scope.gettypenews = function (id) {
        $scope.page = 1;
        $scope.rows = 10;
        $scope.typeid = id;
        fac.get("新闻类型", "News/GetAllNewsType", function (data) {
            for (var i = 0; i < data.length; i++) {
                if (id == data[i].ID) window.localStorage.setItem("newstypeid", i);
            }
        })
        window.localStorage.setItem("newsid", id)
        window.localStorage.setItem("title", "")
        fac.get("新闻分页", "News/GetMorePage?title=&typeid=" + id + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            for (var i = 0; i < data.length; i++) {
                if (data[i].T_NEWS.SHOW_TITLE == null) {
                    data[i].isimg = false;
                } else {
                    data[i].isimg = true;
                }
            }
            $scope.news = data;
        })
        fac.get("新闻分页", "News/GetMoreBig?typeid=" + id, function (data) {
            $scope.imgs = data;
        })
    }
    $scope.getdata = function () {
        $scope.page = window.localStorage.getItem("page");
        $scope.page++;
        window.localStorage.setItem("page", $scope.page);
        var typepage = window.localStorage.getItem("typepage");
        for (var i = 0; i < $scope.newstype.length; i++) {
            if (typepage == i) {
                window.localStorage.setItem("newsid", $scope.newstype[i].ID);
            }
        }
        var id = window.localStorage.getItem("newsid");
        var title = window.localStorage.getItem("title");
        fac.get("获取新闻", "News/GetNewsAll?title=" + title + "&typeid=" + id + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            for (var i = 0; i < data.length; i++) {
                for (var j = 0; j < data[i].newslist.length; j++) {
                    if (data[i].newslist[j].T_NEWS.SHOW_TITLE == null) {
                        data[i].newslist[j].isimg = false;
                    } else {
                        data[i].newslist[j].isimg = true;
                        //data[i].newslist[j].T_NEWS.SHOW_TITLE = "http://bs.nbjs.gov.cn/Upload/image/20150430/QQ%E6%88%AA%E5%9B%BE201504300845246356598038555482075177268.png"
                    }
                }
                $scope.newsall[i].newslist = $scope.newsall[i].newslist.concat(data[i].newslist);
            }
        })
    }
    $scope.detail = function (id) {
        $location.path("/newsdetail/" + id);
    }
}]);
//新闻详细
app.controller("NewsDetailController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {
    fac.deviceready("新闻详细", function () {
        //fac.accessStatistics("#/newsdetail");
        fac.get("新闻详细", "News/Getinfo/" + $routeParams.id, function (data) {
            $scope.info = data;
            if (data.ISCOL) {
                $(".bottom_5").addClass("on");
            }
            if (data.ISZAN) {
                $(".bottom_6").addClass("on");
            }
            //MessageApp.shareSDK({
            //    title: data.T_NEWS.TITLE,
            //    url: data.URL,
            //    image_path: data.T_NEWS.SHOW_TITLE == "-" ? "-" : data.T_NEWS.SHOW_TITLE,
            //    text: data.S_CONTENT
            //});
            //var con = data.T_NEWS.CONTENT.replace(/img style=".*px"\s/, "img style='width:100%;height:auto' ");
            //var con = data.T_NEWS.CONTENT.replace(/img style=".*px"\s/, "img style='WIDTH:100%;HEIGHT:auto' ");
            $("#content").html(data.T_NEWS.CONTENT);
        });
        //$scope.gotype = function (type) {
        //    window.localStorage.setItem("newstype", type);
        //    $location.path("/newslist")
        //}
        $scope.zan = function () {
            if ($(".bottom_6").hasClass("on")) {
                fac.get("取消新闻点赞", "News/DelZan?newsid=" + $routeParams.id, function (data) {
                    //alert("取消点赞成功");
                    $(".bottom_6").removeClass("on");
                });
            } else {
                fac.get("新闻点赞", "News/Zan?newsid=" + $routeParams.id, function (data) {
                    //alert("点赞成功");
                    $(".bottom_6").addClass("on");
                });
            }
        }
        $scope.collect = function () {
            if ($(".bottom_5").hasClass("on")) {
                fac.get("取消新闻收藏", "News/DelCollect?newsid=" + $routeParams.id, function (data) {
                    //alert("取消收藏成功");
                    $(".bottom_5").removeClass("on");
                });
            } else {
                fac.get("新闻收藏", "News/Collect?newsid=" + $routeParams.id, function (data) {
                    //alert("收藏成功");
                    $(".bottom_5").addClass("on");
                });
            }
        }
    })
}]);
//公告列表
app.controller("NoticeListController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {

    //$scope.back = function () {
    //    $location.path("/");
    //}
    fac.accessStatistics("#/noticelist");
    //最新公告
    $scope.page = 1;
    $scope.page2 = 1;
    $scope.rows = 10;
    fac.get("获得公告", "Notice/GetNative?pageIndex=" + $scope.page + "&pageSize=" + $scope.rows + "&timeStamp=", function (data) {
        $scope.notices = data;
    });
    $scope.getdata = function () {
        $scope.page++;
        fac.get("获得公告", "Notice/GetMoreByName?pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            $scope.notices = $scope.notices.concat(data);
        });
    }
    //我的收藏
    fac.get("获得收藏公告", "Notice/GetNative_Collect?pageIndex=" + $scope.page2 + "&pageSize=" + $scope.rows + "&timeStamp=", function (data) {
        $scope.cares = data;
    });
    $scope.getdata2 = function () {
        $scope.page2++;
        fac.get("获得收藏公告", "Notice/GetNoticeByCustomer?pageIndex=" + $scope.page2 + "&pageSize=" + $scope.rows, function (data) {
            $scope.notices = $scope.notices.concat(data);
        });
    }
    $scope.detail = function (id) {
        $location.path("/noticedetail/" + id);
    }
}]);
//公告详细
app.controller("NoticeDetailController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {

    //$scope.back = function () {
    //    $location.path("/noticelist");
    //}
    //fac.accessStatistics("#/noticedetail");
    fac.get("获得公告详细", "Notice/Get/" + $routeParams.id, function (data) {
        $scope.info = data;
        $("#content").html(data.CONTENT);
        //$scope.info = data.T_NOTICE;
        //$("#content").html(data.T_NOTICE.CONTENT);
        //if (data.ISCOL) {
        //    $(".container-title-like").addClass("on");
        //}
        var h1 = window.innerHeight;
        if ($(".new-con").height() < (h1 - 50)) {
            $(".new-con").height(h1 - 50)
        }
    });
    fac.get("公告是否收藏", "Notice/GetCollect?noticeid=" + $routeParams.id, function (data) {
        if (data) {
            $(".container-title-like").addClass("on");
        }
    });
    $scope.collect = function () {
        if ($(".container-title-like").hasClass("on")) {
            fac.get("取消公告收藏", "Notice/DelCollect?noticeid=" + $routeParams.id, function (data) {
                alert("取消收藏成功");
                $(".container-title-like").removeClass("on");
            });
        } else {
            fac.get("收藏公告", "Notice/CollectionNotice?noticeid=" + $routeParams.id, function (data) {
                alert("收藏成功");
                $(".container-title-like").addClass("on");
            });
        }
    }
}]);
//装修备案
app.controller("DecoController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("装修备案", function () {
        //fac.accessStatistics("#/deco");
    });
}]);
//装修备案点列表
app.controller("DecoPointController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {
    fac.deviceready("装修备案点", function () {
        //fac.accessStatistics("#/apointlist");
        window.localStorage.setItem("decopoint", $routeParams.area);
        //$scope.back = function () {
        //    $location.path("/deco")
        //}
        if ($routeParams.point == 0) {
            var lon = window.localStorage.getItem("g_lng");
            var lat = window.localStorage.getItem("g_lat");
            var area = "";
        } else {
            var xy = $routeParams.point.split(",");
            var x = xy[0];
            var y = xy[1];
            var lon = x;
            var lat = y;
            var area = "";
        }
        fac.get("区县", "RecordPoint/GetArea?id=&codetypeid=", function (data) {
            $scope.quxian = data;
        });
        $scope.street = null;
        $scope.block = null;
        $scope.getstreet = function (qu) {
            if (qu == null) {
                $scope.street = null;
                $scope.block = null;
            } else {
                fac.get("街道", "RecordPoint/GetArea?id=" + qu + "&codetypeid=" + 3, function (data2) {
                    $scope.street = data2;
                });
            }
        }
        $scope.getblock = function (street) {
            if (street == null) {
                $scope.block = null;
            } else {
                fac.get("社区", "RecordPoint/GetArea?id=" + street + "&codetypeid=" + 4, function (data3) {
                    $scope.block = data3;
                });
            }
        }
        $scope.find1 = function () {
            if ($scope.name == null || $scope.name == undefined) {
                $scope.name = "";
            }
            var area = window.localStorage.getItem("decopoint")
            if (area == null || area == undefined) {
                area = "";
            }
            if ($routeParams.point == 0) {
                var lon = window.localStorage.getItem("g_lng");
                var lat = window.localStorage.getItem("g_lat");
            } else {
                var xy = $routeParams.point.split(",");
                var x = xy[0];
                var y = xy[1];
                var lon = x;
                var lat = y;
            }
            $scope.page = 1;
            $scope.rows = 10;
            if ($routeParams.baidu == "0") {
                fac.get("装修备案点", "RecordPoint/GetRecordPointPage?lon=" + lon + "&lat=" + lat + "&area=" + area + "&name=" + $scope.name + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].Distance == null || data[i].Distance == undefined) {
                            data[i].Distance = "定位失败";
                        }
                    }
                    $scope.list = data;
                });
            } else {
                fac.get("装修备案点百度", "RecordPoint/GetRecordPointPageBaidu?lon=" + lon + "&lat=" + lat + "&area=" + area + "&name=" + $scope.name + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].Distance == null || data[i].Distance == undefined) {
                            data[i].Distance = "定位失败";
                        }
                    }
                    $scope.list = data;
                });
            }
        }
        $scope.find2 = function () {
            if ($scope.qx == null) {
                var area = null
                window.localStorage.setItem("decopoint", area)
            } else if ($scope.jd == null) {
                var area = $scope.qx
                window.localStorage.setItem("decopoint", area)
            } else if ($scope.sq == null) {
                var area = $scope.jd
                window.localStorage.setItem("decopoint", area)
            } else {
                var area = $scope.sq
                window.localStorage.setItem("decopoint", area)
            }
            var area = window.localStorage.getItem("decopoint")
            if ($routeParams.point == 0) {
                var lon = window.localStorage.getItem("g_lng");
                var lat = window.localStorage.getItem("g_lat");
            } else {
                var xy = $routeParams.point.split(",");
                var x = xy[0];
                var y = xy[1];
                var lon = x;
                var lat = y;
            }
            $scope.page = 1;
            $scope.rows = 10;
            if ($routeParams.baidu == "0") {
                fac.get("装修备案点", "RecordPoint/GetRecordPointPage?lon=" + lon + "&lat=" + lat + "&area=" + area + "&name=&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].Distance == null || data[i].Distance == undefined) {
                            data[i].Distance = "定位失败";
                        }
                    }
                    $scope.list = data;
                });
            } else {
                fac.get("装修备案点百度", "RecordPoint/GetRecordPointPageBaidu?lon=" + lon + "&lat=" + lat + "&area=" + area + "&name=&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].Distance == null || data[i].Distance == undefined) {
                            data[i].Distance = "定位失败";
                        }
                    }
                    $scope.list = data;
                });
            }
        }
        $scope.page = 1;
        $scope.rows = 10;
        if ($routeParams.baidu == "0") {
            fac.get("装修备案点", "RecordPoint/GetRecordPointPage?lon=" + lon + "&lat=" + lat + "&area=" + area + "&name=&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                for (var i = 0; i < data.length; i++) {
                    if (data[i].Distance == null || data[i].Distance == undefined) {
                        data[i].Distance = "定位失败";
                    }
                }
                $scope.list = data;
            });
        } else {
            fac.get("装修备案点百度", "RecordPoint/GetRecordPointPageBaidu?lon=" + lon + "&lat=" + lat + "&area=" + area + "&name=&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                for (var i = 0; i < data.length; i++) {
                    if (data[i].Distance == null || data[i].Distance == undefined) {
                        data[i].Distance = "定位失败";
                    }
                }
                $scope.list = data;
            });
        }
        $scope.del = function () {
            $scope.name = "";
        }
        $scope.getdata = function () {
            $scope.page++;
            if ($routeParams.point == 0) {
                var lon = window.localStorage.getItem("g_lng");
                var lat = window.localStorage.getItem("g_lat");
            } else {
                var xy = $routeParams.point.split(",");
                var x = xy[0];
                var y = xy[1];
                var lon = x;
                var lat = y;
            }
            var area = window.localStorage.getItem("decopoint");
            if ($routeParams.baidu == "0") {
                fac.get("装修备案点", "RecordPoint/GetRecordPointPage?lon=" + lon + "&lat=" + lat + "&area=" + area + "&name=" + $scope.name + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].Distance == null || data[i].Distance == undefined) {
                            data[i].Distance = "定位失败";
                        }
                    }
                    $scope.list = $scope.list.concat(data);
                });
            } else {
                fac.get("装修备案点百度", "RecordPoint/GetRecordPointPageBaidu?lon=" + lon + "&lat=" + lat + "&area=" + area + "&name=" + $scope.name + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].Distance == null || data[i].Distance == undefined) {
                            data[i].Distance = "定位失败";
                        }
                    }
                    $scope.list = $scope.list.concat(data);
                });
            }
        }
        $scope.local = function (point) {
            if (point == "" || point == null || point == undefined) {
                alert("当前备案点无坐标，无法定位")
            } else {
                $location.path("/pointmap/" + point);
            }
        }
    });
}]);
//备案点地图
app.controller("PointMapController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {
    fac.deviceready("备案点位置", function () {
        //fac.accessStatistics("#/pointmap");
        $scope.chose = function () {
            var mark = window.localStorage.getItem("opoint");
            var point = JSON.parse(mark)
            var ll = point.lng + "," + point.lat;
            $location.path("/decopoint/" + ll + "/1")
        }
    });
}]);
//我要备案
app.controller("DecoApplyController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("我要备案", function () {
        //fac.accessStatistics("#/decoapply");
        $scope.back = function () {
            if ($("[class^='page']:visible").index() == 1) {
                //$location.path("/deco")
                fac.trackRecord.back($location);
            } else {
                $("[class^='page']:visible").hide().prev().show();
            }
        }
        $scope.id = null;
        //$scope.Btime = null;
        var lon = window.localStorage.getItem("g_lng");
        var lat = window.localStorage.getItem("g_lat");
        var area = "江东区";
        $scope.page = 1;
        $scope.rows = 10;
        window.localStorage.removeItem("deconame");
        fac.get("备案点", "RecordPoint/GetRecordPointPage?lon=" + lon + "&lat=" + lat + "&area=" + area + "&name=&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            $scope.list = data;
        });
        $scope.getdata = function () {
            $scope.page++;
            var name = window.localStorage.getItem("deconame");
            fac.get("备案点", "RecordPoint/GetRecordPointPage?lon=" + lon + "&lat=" + lat + "&area=" + area + "&name=" + name + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                $scope.list = $scope.list.concat(data);
            });
        }
        $scope.chose = function (id) {
            $(".page1 .new-con").each(function () {
                $(this).removeClass("on");
            })
            $("#" + id).addClass("on");
            $scope.id = id;
        }
        $scope.next1 = function () {
            if ($scope.id != null) {
                $(".page1").hide();
                $(".page2").show();
            } else {
                alert("请先选择备案点");
                return;
            }
            fac.get("备案点单个", "RecordPoint/Get/" + $scope.id, function (data) {
                $scope.data = data;
            });
        }
        $scope.next2 = function () {
            if ($scope.Recorder == "" || $scope.Recorder == null) {
                alert("备案人姓名不能为空");
                return;
            }
            $(".page2").hide();
            $(".page3").show();
        }
        $scope.sendstatus = 0;
        $scope.yzmstatus = 1;
        $scope.getyzm = function () {
            if ($scope.HousRecorderTel == null || $scope.HousRecorderTel == "" || $scope.HousRecorderTel == undefined) {
                alert("手机号不能为空");
                return;
            }
            if (!/^1[3|4|5|7|8]\d{9}$/.test($scope.HousRecorderTel)) {
                alert("手机号格式错误");
            } else {
                if ($scope.yzmstatus) {
                    $scope.yzmstatus = 0;
                    var vcode_time = 30;
                    var vcode_id = $("#tel");
                    if ($(vcode_id).hasClass('on')) { } else {
                        $(vcode_id).addClass("on");
                        var msg_num = setInterval(function () {
                            $(vcode_id).find("a").html(vcode_time + "秒后重发");
                            vcode_time = vcode_time - 1
                            if (vcode_time == 0) {
                                clearInterval(msg_num);
                                $(vcode_id).find("a").html("重新获取");
                                $scope.yzmstatus = 1;
                                vcode_time = vcode_time;
                                $(vcode_id).removeClass("on");
                            }
                        }, 1000)
                    }
                    fac.get("获得验证码", "verification/Send?tel=" + $scope.HousRecorderTel, function (data) {
                        if (data.type) {
                            alert(data.msg);
                            //$scope.yzmstatus = 0;
                            //var vcode_time = 30;
                            //var vcode_id = $("#tel");
                            //if ($(vcode_id).hasClass('on')) { } else {
                            //    $(vcode_id).addClass("on");
                            //    var msg_num = setInterval(function () {
                            //        $(vcode_id).find("a").html(vcode_time + "秒后重发");
                            //        vcode_time = vcode_time - 1
                            //        if (vcode_time == 0) {
                            //            clearInterval(msg_num);
                            //            $(vcode_id).find("a").html("重新获取");
                            //            $scope.yzmstatus = 1;
                            //            vcode_time = vcode_time;
                            //            $(vcode_id).removeClass("on");
                            //        }
                            //    }, 1000)
                            //}
                            $scope.sendstatus = 1;
                        } else {
                            alert(data.msg);
                        }
                    });
                }
            }
        }
        $scope.next3 = function () {
            if ($scope.sendstatus) {
                if (!/^\d{6}$/.test($scope.yzm)) {
                    alert("手机验证码格式错误");
                    return;
                }
                fac.get("验证验证码", "verification/verificationcode?tel=" + $scope.HousRecorderTel + "&code=" + $scope.yzm, function (data) {
                    if (data == true) {
                        $(".page3").hide();
                        $(".page4").show();
                    } else {
                        alert("手机验证码错误");
                        return;
                    }
                });
            } else {
                alert("请先发送验证码");
            }
        }
        $scope.next4 = function () {
            if ($scope.HouseAddress == "" || $scope.HouseAddress == null) {
                alert("装修地址不能为空");
                return;
            }
            $(".page4").hide();
            $(".page6").show();
            //$(".page5").show();
        }
        //$scope.next5 = function () {
        //    var DecorationStart = document.getElementById("btime").value;
        //    if (DecorationStart == "" || DecorationStart == null) {
        //        alert("开始装修时间不能为空");
        //        return;
        //    }
        //    $scope.Btime = DecorationStart;
        //    $(".page5").hide();
        //    $(".page6").show();
        //}
        $scope.sub = function () {
            var user = window.localStorage.getItem("User");
            var model = new Object();
            model.BeiDeptID = $scope.id;
            model.Recorder = $scope.Recorder;
            model.HousRecorderTel = $scope.HousRecorderTel;
            model.HouseAddress = $scope.HouseAddress;
            //model.DecorationStart = $scope.Btime;
            //$http.get(sytdapp.APPHOST+"Housing/AddHousing?model=" + model + "&openid=").success(function (data) {
            fac.post("提交预备案", "Housing/AddHousing", function (data) {
                if (data.level == 0) {
                    alert("备案成功");
                    //$location.path("/");
                    fac.redirect2Index();
                }
            }, {
                data: model
            });
        }
    })
}]);
//房屋巡查
app.controller("PatrolController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {

    //$scope.back = function () {
    //    $location.path("/");
    //}
    //fac.accessStatistics("#/patrol");
    fac.get("验证是否绑定宽易", "Customer/yzkybinged", function (data) {
        if (data == false) {
            $location.path("/bindky");
        }
    });
}]);
//备案点（定位/重新定位）
app.controller("RePointController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {

    //fac.accessStatistics("#/repoint");
    //$scope.back = function () {
    //    $location.path("/patrol")
    //}
    //有定位获得经纬度和地区
    var lon = window.localStorage.getItem("g_lng");
    var lat = window.localStorage.getItem("g_lat");
    window.localStorage.setItem("decopoint", "")
    var area = "";
    fac.get("区县", "RecordPoint/GetArea?id=&codetypeid=", function (data) {
        $scope.quxian = data;
    });
    $scope.street = null;
    $scope.block = null;
    $scope.getstreet = function (qu) {
        if (qu == null) {
            $scope.street = null;
            $scope.block = null;
        } else {
            fac.get("街道", "RecordPoint/GetArea?id=" + qu + "&codetypeid=" + 3, function (data2) {
                $scope.street = data2;
            });
        }
    }
    $scope.getblock = function (street) {
        if (street == null) {
            $scope.block = null;
        } else {
            fac.get("社区", "RecordPoint/GetArea?id=" + street + "&codetypeid=" + 4, function (data3) {
                $scope.block = data3;
            });
        }
    }
    $scope.find1 = function () {
        if ($scope.name == null || $scope.name == undefined) {
            $scope.name = "";
        }
        var area = window.localStorage.getItem("decopoint")
        if (area == null || area == undefined) {
            area = "";
        }
        var lon = window.localStorage.getItem("g_lng");
        var lat = window.localStorage.getItem("g_lat");
        fac.get("装修备案点", "RecordPoint/GetRecordPointPage?lon=" + lon + "&lat=" + lat + "&area=" + area + "&name=" + $scope.name + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            for (var i = 0; i < data.length; i++) {
                if (data[i].Distance == null || data[i].Distance == undefined) {
                    data[i].Distance = "定位失败";
                }
            }
            $scope.list = data;
        });
    }
    $scope.find2 = function () {
        if ($scope.qx == null) {
            alert("请输入区县");
            return;
        } else if ($scope.jd == null) {
            var area = $scope.qx
            window.localStorage.setItem("decopoint", area)
        } else if ($scope.sq == null) {
            var area = $scope.jd
            window.localStorage.setItem("decopoint", area)
        } else {
            var area = $scope.sq
            window.localStorage.setItem("decopoint", area)
        }
        var area = window.localStorage.getItem("decopoint")
        var lon = window.localStorage.getItem("g_lng");
        var lat = window.localStorage.getItem("g_lat");
        $scope.page = 1;
        $scope.rows = 10;
        fac.get("装修备案点", "RecordPoint/GetRecordPointPage?lon=" + lon + "&lat=" + lat + "&area=" + area + "&name=&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            for (var i = 0; i < data.length; i++) {
                if (data[i].Distance == null || data[i].Distance == undefined) {
                    data[i].Distance = "定位失败";
                }
            }
            $scope.list = data;
        });
    }
    $scope.page = 1;
    $scope.rows = 10;
    fac.get("装修备案点", "RecordPoint/GetRecordPointPage?lon=" + lon + "&lat=" + lat + "&area=" + area + "&name=&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
        for (var i = 0; i < data.length; i++) {
            if (data[i].Distance == null || data[i].Distance == undefined) {
                data[i].Distance = "定位失败";
            }
        }
        $scope.list = data;
    });
    $scope.getdata = function () {
        $scope.page++;
        var area = window.localStorage.getItem("decopoint");
        fac.get("装修备案点", "RecordPoint/GetRecordPointPage?lon=" + lon + "&lat=" + lat + "&area=" + area + "&name=&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            for (var i = 0; i < data.length; i++) {
                if (data[i].Distance == null || data[i].Distance == undefined) {
                    data[i].Distance = "定位失败";
                }
            }
            $scope.list = $scope.list.concat(data);
        });
    }
    $scope.local = function (id) {
        $location.path("/repointmap/" + id);
    }
}]);
//备案点（定位/重新定位）地图
app.controller("RePointMapController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {

    //fac.accessStatistics("#/repointmap");
    //$scope.back = function () {
    //    history.back();
    //}
    $scope.sub = function () {
        var id = $routeParams.id;
        var lng = window.localStorage.getItem("repointx");
        var lat = window.localStorage.getItem("repointy");
        var baidulng = window.localStorage.getItem("repointbaidux");
        var baidulat = window.localStorage.getItem("repointbaiduy");
        fac.get("备案点重定位", "RecordPoint/SetPoint?decorationID=" + id + "&lon=" + lng + "&lat=" + lat + "&baidulon=" + baidulng + "&baidulat=" + baidulat, function (data) {
            if (data.level == 0) {
                alert("定位成功");
                $location.path("/repoint");
            }
        })
    }
}]);
//装修备案登记列表
app.controller("DecoLogController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("装修备案登记", function () {
        //fac.accessStatistics("#/decolog");
        //$scope.back = function () {
        //    $location.path("/patrol")
        //}
        $scope.page = 1;
        $scope.rows = 10;
        window.localStorage.setItem("decoaddr", "");
        window.localStorage.setItem("deconame", "");
        window.localStorage.setItem("tel", "");
        fac.get("获得备案列表", "Housing/GetYuBeiAn?zuoluo=&name=&tel=&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            $scope.list = data.value;
        });
        $scope.getdata = function () {
            $scope.page++;
            var decoaddr = window.localStorage.getItem("decoaddr");
            var deconame = window.localStorage.getItem("deconame");
            var decotel = window.localStorage.getItem("decotel");
            fac.get("获得备案列表", "Housing/GetYuBeiAn?zuoluo=" + decoaddr + "&name=" + deconame + "&tel=" + decotel + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                $scope.list = $scope.list.concat(data.value);
            });
        }
        $scope.find1 = function () {
            if ($scope.address1 == undefined || $scope.address1 == null) {
                $scope.address1 = "";
            }
            $scope.page = 1;
            $scope.rows = 10;
            window.localStorage.setItem("decoaddr", $scope.address1);
            fac.get("获得备案列表", "Housing/GetYuBeiAn?zuoluo=" + $scope.address1 + "&name=&tel=&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                $scope.list = data.value;
            });
        }
        $scope.find2 = function () {
            if ($scope.address2 == undefined || $scope.address2 == null) {
                $scope.address2 = "";
            }
            if ($scope.name == undefined || $scope.name == null) {
                $scope.name = "";
            }
            if ($scope.tel == undefined || $scope.tel == null) {
                $scope.tel = "";
            }
            $scope.page = 1;
            $scope.rows = 10;
            window.localStorage.setItem("decoaddr", $scope.address2);
            window.localStorage.setItem("deconame", $scope.name);
            window.localStorage.setItem("tel", $scope.tel);
            fac.get("获得备案列表", "Housing/GetYuBeiAn?zuoluo=" + $scope.address2 + "&name=" + $scope.name + "&tel=" + $scope.tel + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                $scope.list = data.value;
            });
        }
        $scope.clean = function () {
            $scope.address1 = "";
        }
        $scope.Done = function () {
            $(".xx_bg").css("height", $(document).height() - 50)
        }
        $scope.chose = function (id) {
            $location.path("/decologd/" + id);
        }
    });
}]);
//装修备案登记详细
app.controller("DecoLogDController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {

    //fac.accessStatistics("#/decologd");
    $scope.back = function () {
        if ($("[class^='page']:visible").index() == 1) {
            var lixian = window.localStorage.getItem("zxba" + $routeParams.id);
            var unupload = window.localStorage.getItem("zxba" + $routeParams.id + "unupload");
            if ((lixian == undefined || lixian == null) && (unupload == undefined || unupload == null)) {
                //$location.path("/decolog");
                fac.trackRecord.back($location);
            } else {
                if (confirm("尚未离线保存,确认退出？")) {
                    //$location.path("/decolog");
                    fac.trackRecord.back($location);
                }
            }
        } else {
            $("[class^='page']:visible").hide().prev().show();
        }
    }
    //获得备案人类型
    fac.get("备案人类型", "Housing/GetMoreRecorderType", function (data) {
        $scope.balx = data.value;
        $scope.RecorderType = data.value[0].CODEID;
    });
    //获得房产性质
    fac.get("房产性质", "Housing/GetMoreHouseNature", function (data) {
        $scope.house = data.value;
        $scope.HouseNature = data.value[0].CODEID;
    });
    //获得装修类型
    fac.get("装修类型", "Housing/GetMoreDecoratorType", function (data) {
        $scope.zhuangx = data.value;
        $scope.DecoratorType = data.value[0].CODEID;
    });
    fac.get("区县", "RecordPoint/GetArea?id=&codetypeid=", function (data) {
        $scope.quxian = data;
        $scope.HouseOwners = new Array();
    });
    var lixian = window.localStorage.getItem("zxba" + $routeParams.id);
    $scope.File1 = new Array();
    $scope.File2 = new Array();
    $scope.File3 = new Array();
    $scope.File4 = new Array();
    $scope.File5 = new Array();
    $scope.File6 = new Array();
    $scope.File7 = new Array();
    $scope.File8 = new Array();
    $scope.File9 = new Array();
    $scope.File10 = new Array();
    $scope.File11 = new Array();
    $scope.File12 = new Array();
    $scope.unupload1 = new Array();
    $scope.unupload2 = new Array();
    $scope.unupload3 = new Array();
    $scope.unupload4 = new Array();
    $scope.unupload5 = new Array();
    $scope.unupload6 = new Array();
    $scope.unupload7 = new Array();
    $scope.unupload8 = new Array();
    $scope.unupload9 = new Array();
    $scope.unupload10 = new Array();
    $scope.unupload11 = new Array();
    $scope.unupload12 = new Array();
    $scope.street = null;
    $scope.block = null;
    $scope.item = null;
    $scope.zhuang = null;
    $scope.single = null;
    $scope.huhao = null;
    $scope.HouseOwners = new Array();
    if (lixian == undefined || lixian == null) {

    } else {
        var data = {
        };
        data.value = JSON.parse(lixian);
        $scope.olddata = data.value;
        $scope.File1 = data.value["File1"];
        $scope.File2 = data.value["File2"];
        $scope.File3 = data.value["File3"];
        $scope.File4 = data.value["File4"];
        $scope.File5 = data.value["File5"];
        $scope.File6 = data.value["File6"];
        $scope.File7 = data.value["File7"];
        $scope.File8 = data.value["File8"];
        $scope.File9 = data.value["File9"];
        $scope.File10 = data.value["File10"];
        $scope.File11 = data.value["File11"];
        $scope.File12 = data.value["File12"];
        $scope.RecorderType = $scope.olddata["rblRecorderType"];
        $scope.Recorder = $scope.olddata["txtRecorder"];
        document.getElementById("DecorationStart").value = $scope.olddata["txtDecorationStart"];
        document.getElementById("DecorationEnd").value = $scope.olddata["txtDecorationEnd"];
        $scope.RecorderTel = $scope.olddata["txtRecorderTel"];
        $scope.RecorderIDCard = $scope.olddata["txtRecorderIDCard"];
        $scope.RecorderAddress = $scope.olddata["txtRecorderAddress"];
        $scope.qx = $scope.olddata["qxid"];
        fac.get("街道", "RecordPoint/GetArea?id=" + $scope.qx + "&codetypeid=" + 3, function (data2) {
            $scope.street = data2;
        });
        $scope.jd = $scope.olddata["jdid"];
        fac.get("社区", "RecordPoint/GetArea?id=" + $scope.jd + "&codetypeid=" + 4, function (data3) {
            $scope.block = data3;
        });
        $scope.sq = $scope.olddata["sqid"];
        fac.get("项目", "RecordPoint/GetArea?id=" + $scope.sq + "&codetypeid=" + 21, function (data4) {
            $scope.item = data4;
        });
        $scope.xm = $scope.olddata["xmid"];
        fac.get("幢", "Housing/GetMoreByProjectCodeID?quxian=" + $scope.qx + "&street=" + $scope.jd + "&block=" + $scope.sq + "&projectCodeid=" + $scope.xm, function (data5) {
            var result = data5.value;
            for (var i = 0; i < result.length; i++) {
                if (result[i].Address != null) {
                    result[i].Address = result[i].Address.replace(/[#]/g, "");
                    result[i].Address = result[i].Address.replace(/[$]/g, "");
                }
            }
            $scope.zhuang = result;
        });
        $scope.zh = $scope.olddata["zhid"];
        fac.get("单元", "Housing/GetMoreDanyuanByHouseid?houseid=" + $scope.zh, function (data6) {
            $scope.single = data6.value;
            $scope.dy = $scope.olddata["dyid"];
            for (var i = 0; i < $scope.single.length; i++) {
                if ($scope.dy == $scope.single[i].DanYuanID) {
                    $scope.huhao = $scope.single[i].HuList;
                }
            }
        });
        //fac.get("户", "Housing/GetMoreHouseHuByHouseid?houseid=" + $scope.zh + "&danyuanid=" + $scope.dy, function (data7) {
        //    $scope.huhao = data7.value;
        //});
        $scope.hu = $scope.olddata["ucHuSelected_LPB"];
        $scope.CertificateNo = $scope.olddata["txtCertificateNo"];
        $scope.CertificateJZMJ = $scope.olddata["txtCertificateJZMJ"];
        $scope.CertificateAddress = $scope.olddata["txtCertificateAddress"];
        $scope.HouseChen = $scope.olddata["txtHouseChen"];
        $scope.HouseNature = $scope.olddata["rblHouseNature"];
        $scope.HouseOwners = $scope.olddata.HouseOwnerList;
        //var houseownerlist = $scope.olddata.HouseOwnerList;
        //for (var i = 0; i < houseownerlist.length; i++) {
        //    var newowner = {
        //    };
        //    newowner.Name = houseownerlist[i].Name;
        //    newowner.IDCard = houseownerlist[i].IDCard;
        //    newowner.Tel = houseownerlist[i].Tel;
        //    $scope.HouseOwners.push(newowner);
        //}
        $scope.DecoratorType = $scope.olddata["hidPerson"];
        if ($scope.DecoratorType == 23263) {
            $("#type1").show();
            $("#type2").hide();
            $scope.DecorationPerson = $scope.olddata["txtDecorationPerson"];
            $scope.DecorationPersonTel = $scope.olddata["txtDecorationPersonTel"];
        } else if ($scope.DecoratorType == 23264) {
            $("#type1").hide();
            $("#type2").show();
            $scope.DecorationUnit = $scope.olddata["txtDecorationUnit"];
            $scope.ProjectManager = $scope.olddata["txtProjectManager"];
            $scope.ProjectManagerTel = $scope.olddata["txtProjectManagerTel"];
        }
        document.getElementById("RecordDate").value = $scope.olddata["txtRecordDate"];
    }
    //fac.get("获得详细备案", "Housing/GetAddHousingFullByYUid?yubeianid=" + $routeParams.id, function (data) {
    //    $scope.info = data.value;

    $scope.getstreet = function (qu) {
        if (qu == null) {
            $scope.street = null;
            $scope.block = null;
            $scope.item = null;
            $scope.zhuang = null;
            $scope.single = null;
            $scope.huhao = null;
        } else {
            fac.get("街道", "RecordPoint/GetArea?id=" + qu + "&codetypeid=" + 3, function (data2) {
                $scope.street = data2;
            });
        }
    }
    $scope.getblock = function (street) {
        if (street == null) {
            $scope.block = null;
            $scope.item = null;
            $scope.zhuang = null;
            $scope.single = null;
            $scope.huhao = null;
        } else {
            fac.get("社区", "RecordPoint/GetArea?id=" + street + "&codetypeid=" + 4, function (data3) {
                $scope.block = data3;
            });
        }
    }
    $scope.getitem = function (block) {
        if (block == null) {
            $scope.item = null;
            $scope.zhuang = null;
            $scope.single = null;
            $scope.huhao = null;
        } else {
            fac.get("项目", "RecordPoint/GetArea?id=" + block + "&codetypeid=" + 21, function (data4) {
                $scope.item = data4;
            });
        }
    }
    $scope.getzhuang = function (item) {
        if (item == null) {
            $scope.zhuang = null;
            $scope.single = null;
            $scope.huhao = null;
        } else {
            fac.get("幢", "Housing/GetMoreByProjectCodeID?quxian=" + $scope.qx + "&street=" + $scope.jd + "&block=" + $scope.sq + "&projectCodeid=" + item, function (data5) {
                var result = data5.value;
                for (var i = 0; i < result.length; i++) {
                    if (result[i].Address != null) {
                        result[i].Address = result[i].Address.replace(/[#]/g, "");
                        result[i].Address = result[i].Address.replace(/[$]/g, "");
                    }
                }
                $scope.zhuang = result;
            });
        }
    }
    $scope.getdy = function (zhuang) {
        if (zhuang == null) {
            $scope.single = null;
            $scope.huhao = null;
        } else {
            window.localStorage.setItem("hid", zhuang);
            fac.get("单元", "Housing/GetMoreDanyuanByHouseid?houseid=" + zhuang, function (data6) {
                $scope.single = data6.value;
            });
        }
    }
    $scope.gethuhao = function (single) {
        if (single == null) {
            $scope.huhao = null;
        } else {
            for (var i = 0; i < $scope.single.length; i++) {
                if (single == $scope.single[i].DanYuanID) {
                    $scope.huhao = $scope.single[i].HuList;
                }
            }
            //var hid = window.localStorage.getItem("hid");
            //fac.get("户", "Housing/GetMoreHouseHuByHouseid?houseid=" + hid + "&danyuanid=" + single, function (data7) {
            //    $scope.huhao = data7.value;
            //});
        }
    }
    //新增产权人
    $scope.addp = function () {
        var newowner = {
        };
        newowner.Name = ""
        newowner.IDCard = "";
        newowner.Tel = "";
        $scope.HouseOwners.push(newowner);
    }
    //保存
    $scope.save = function (id) {
        var name = document.getElementById("Name" + id).value;
        var idcard = document.getElementById("IDCard" + id).value;
        var tel = document.getElementById("Tel" + id).value;
        if (name == null || name == "") {
            alert("产权人姓名不能为空");
            return
        }
        if (!/^1[3|4|5|7|8]\d{9}$/.test(tel)) {
            alert("产权人手机号格式错误");
            return;
        }
        if (!/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(idcard)) {
            alert("产权人身份证格式错误");
            return;
        }
        $scope.HouseOwners[id].Name = name;
        $scope.HouseOwners[id].IDCard = idcard;
        $scope.HouseOwners[id].Tel = tel;
    }
    //删除
    $scope.del = function (id) {
        $scope.HouseOwners.remove(id);
    }
    $scope.ch1 = function () {
        if ($scope.DecoratorType == 23263) {
            $("#type1").show();
            $("#ty1").show;
            $("#ty2").hide;
            $("#type2").hide();
        } else if ($scope.DecoratorType == 23264) {
            $("#type1").hide();
            $("#type2").show();
            $("#ty2").show;
            $("#ty1").hide;
        }
    }

    $scope.Done1 = function () {

    }
    //$(".input-style1 input").click(function () {
    //    var id = $(this).attr("id").replace("Rinput-", "")
    //    window.localStorage.setItem("fjid", id);
    //})
    $(".add-img").click(function () {
        var id = $(this).attr("id").replace("addimg", "");
        window.localStorage.setItem("fjid", id);
        var title = $(this).parent().parent().parent().prev().html();
        if (title == undefined) {
            var title = $(this).parent().parent().parent().find("span").html();
        }
        $("#title").html(title)
        $(".speak").show();
    })
    $scope.takeimg = function () {
        var fjid = window.localStorage.getItem("fjid");
        if (fjid == null || fjid == undefined) {
            alert("请先选择区域");
            return;
        }
        var csimage = "csimage";
        var fj = {
            "type": 1, "data": csimage
        };
        if (fjid == "1") {
            $scope.unupload1.push(fj);
            $scope.File1.push({
                "FileGuid": 1, "FullName": csimage, "Url": "www.baidu.com"
            });
        } else if (fjid == "2") {
            $scope.unupload2.push(fj);
            $scope.File2.push({
                "FileGuid": 2, "FullName": csimage, "Url": "www.baidu.com"
            });
        } else if (fjid == "3") {
            $scope.unupload3.push(fj);
            $scope.File3.push({
                "FileGuid": 3, "FullName": csimage, "Url": "www.baidu.com"
            });
        } else if (fjid == "4") {
            $scope.unupload4.push(fj);
            $scope.File4.push({
                "FileGuid": 4, "FullName": csimage, "Url": "www.baidu.com"
            });
        } else if (fjid == "5") {
            $scope.unupload5.push(fj);
            $scope.File5.push({
                "FileGuid": 5, "FullName": csimage, "Url": "www.baidu.com"
            });
        } else if (fjid == "6") {
            $scope.unupload6.push(fj);
            $scope.File6.push({
                "FileGuid": 6, "FullName": csimage, "Url": "www.baidu.com"
            });
        } else if (fjid == "7") {
            $scope.unupload7.push(fj);
            $scope.File7.push({
                "FileGuid": 7, "FullName": csimage, "Url": "www.baidu.com"
            });
        } else if (fjid == "8") {
            $scope.unupload8.push(fj);
            $scope.File8.push({
                "FileGuid": 8, "FullName": csimage, "Url": "www.baidu.com"
            });
        } else if (fjid == "9") {
            $scope.unupload9.push(fj);
            $scope.File9.push({
                "FileGuid": 9, "FullName": csimage, "Url": "www.baidu.com"
            });
        } else if (fjid == "10") {
            $scope.unupload10.push(fj);
            $scope.File10.push({
                "FileGuid": 10, "FullName": csimage, "Url": "www.baidu.com"
            });
        } else if (fjid == "11") {
            $scope.unupload11.push(fj);
            $scope.File11.push({
                "FileGuid": 11, "FullName": csimage, "Url": "www.baidu.com"
            });
        } else if (fjid == "12") {
            $scope.unupload12.push(fj);
            $scope.File12.push({
                "FileGuid": 12, "FullName": csimage, "Url": "www.baidu.com"
            });
        }
        //WebcamApp.doWebcamApp("photo", "http://fileupload.openxt.com/ueditor/controller.ashx", {
        //    action: "uploadimage"
        //}, false, function (code) {
        //    var data = JSON.parse(code);
        //    var fj = {
        //        "type": 1, "data": data[0]
        //    };
        //    var fjid = window.localStorage.getItem("fjid");
        //    if (fjid == null || fjid == undefined) {
        //        alert("请先选择区域");
        //        return;
        //    }
        //    PreviewPictureApp.doPreviewPicture(data[0], function (success) {
        //        var result = "data:image/jpg;base64," + success;
        //        alert(result)
        //        if (fjid == "1") {
        //            $scope.unupload1.push(fj);
        //            $scope.File1.push({
        //                "FileGuid": 1, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "2") {
        //            $scope.unupload2.push(fj);
        //            $scope.File2.push({
        //                "FileGuid": 2, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "3") {
        //            $scope.unupload3.push(fj);
        //            $scope.File3.push({
        //                "FileGuid": 3, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "4") {
        //            $scope.unupload4.push(fj);
        //            $scope.File4.push({
        //                "FileGuid": 4, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "5") {
        //            $scope.unupload5.push(fj);
        //            $scope.File5.push({
        //                "FileGuid": 5, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "6") {
        //            $scope.unupload6.push(fj);
        //            $scope.File6.push({
        //                "FileGuid": 6, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "7") {
        //            $scope.unupload7.push(fj);
        //            $scope.File7.push({
        //                "FileGuid": 7, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "8") {
        //            $scope.unupload8.push(fj);
        //            $scope.File8.push({
        //                "FileGuid": 8, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "9") {
        //            $scope.unupload9.push(fj);
        //            $scope.File9.push({
        //                "FileGuid": 9, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "10") {
        //            $scope.unupload10.push(fj);
        //            $scope.File10.push({
        //                "FileGuid": 10, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "11") {
        //            $scope.unupload11.push(fj);
        //            $scope.File11.push({
        //                "FileGuid": 11, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "12") {
        //            $scope.unupload12.push(fj);
        //            $scope.File12.push({
        //                "FileGuid": 12, "FullName": data[0], "Url": result
        //            });
        //        }
        //    })
        //}, function (error) {
        //    alert("保存失败");
        //    return;
        //});
    }
    $scope.upimg = function () {
        var fjid = window.localStorage.getItem("fjid");
        if (fjid == null || fjid == undefined) {
            alert("请先选择区域");
            return;
        }
        var csimg = "csimg";
        var fj = {
            "type": 1, "data": csimg
        };
        if (fjid == "1") {
            $scope.unupload1.push(fj);
            $scope.File1.push({
                "FileGuid": 1, "FullName": csimg, "Url": "www.google.com"
            });
        } else if (fjid == "2") {
            $scope.unupload2.push(fj);
            $scope.File2.push({
                "FileGuid": 2, "FullName": csimg, "Url": "www.google.com"
            });
        } else if (fjid == "3") {
            $scope.unupload3.push(fj);
            $scope.File3.push({
                "FileGuid": 3, "FullName": csimg, "Url": "www.google.com"
            });
        } else if (fjid == "4") {
            $scope.unupload4.push(fj);
            $scope.File4.push({
                "FileGuid": 4, "FullName": csimg, "Url": "www.google.com"
            });
        } else if (fjid == "5") {
            $scope.unupload5.push(fj);
            $scope.File5.push({
                "FileGuid": 5, "FullName": csimg, "Url": "www.google.com"
            });
        } else if (fjid == "6") {
            $scope.unupload6.push(fj);
            $scope.File6.push({
                "FileGuid": 6, "FullName": csimg, "Url": "www.google.com"
            });
        } else if (fjid == "7") {
            $scope.unupload7.push(fj);
            $scope.File7.push({
                "FileGuid": 7, "FullName": csimg, "Url": "www.google.com"
            });
        } else if (fjid == "8") {
            $scope.unupload8.push(fj);
            $scope.File8.push({
                "FileGuid": 8, "FullName": csimg, "Url": "www.google.com"
            });
        } else if (fjid == "9") {
            $scope.unupload9.push(fj);
            $scope.File9.push({
                "FileGuid": 9, "FullName": csimg, "Url": "www.google.com"
            });
        } else if (fjid == "10") {
            $scope.unupload10.push(fj);
            $scope.File10.push({
                "FileGuid": 10, "FullName": csimg, "Url": "www.google.com"
            });
        } else if (fjid == "11") {
            $scope.unupload11.push(fj);
            $scope.File11.push({
                "FileGuid": 11, "FullName": csimg, "Url": "www.google.com"
            });
        } else if (fjid == "12") {
            $scope.unupload12.push(fj);
            $scope.File12.push({
                "FileGuid": 12, "FullName": csimg, "Url": "www.google.com"
            });
        }
        //FileUploadApp.doFileUploadApp("http://fileupload.openxt.com/ueditor/controller.ashx", {
        //    action: "uploadimage"
        //}, "*", false, function (str) {
        //    var data = JSON.parse(str);
        //    var fj = {
        //        "type": 1, "data": data[0]
        //    };
        //    var fjid = window.localStorage.getItem("fjid");
        //    if (fjid == null || fjid == undefined) {
        //        alert("请先选择区域");
        //        return;
        //    }
        //    PreviewPictureApp.doPreviewPicture(data[0], function (success) {
        //        var result = "data:image/jpg;base64," + success;
        //        if (fjid == "1") {
        //            $scope.unupload1.push(fj);
        //            $scope.File1.push({
        //                "FileGuid": 1, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "2") {
        //            $scope.unupload2.push(fj);
        //            $scope.File2.push({
        //                "FileGuid": 2, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "3") {
        //            $scope.unupload3.push(fj);
        //            $scope.File3.push({
        //                "FileGuid": 3, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "4") {
        //            $scope.unupload4.push(fj);
        //            $scope.File4.push({
        //                "FileGuid": 4, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "5") {
        //            $scope.unupload5.push(fj);
        //            $scope.File5.push({
        //                "FileGuid": 5, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "6") {
        //            $scope.unupload6.push(fj);
        //            $scope.File6.push({
        //                "FileGuid": 6, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "7") {
        //            $scope.unupload7.push(fj);
        //            $scope.File7.push({
        //                "FileGuid": 7, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "8") {
        //            $scope.unupload8.push(fj);
        //            $scope.File8.push({
        //                "FileGuid": 8, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "9") {
        //            $scope.unupload9.push(fj);
        //            $scope.File9.push({
        //                "FileGuid": 9, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "10") {
        //            $scope.unupload10.push(fj);
        //            $scope.File10.push({
        //                "FileGuid": 10, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "11") {
        //            $scope.unupload11.push(fj);
        //            $scope.File11.push({
        //                "FileGuid": 11, "FullName": data[0], "Url": result
        //            });
        //        } else if (fjid == "12") {
        //            $scope.unupload12.push(fj);
        //            $scope.File12.push({
        //                "FileGuid": 12, "FullName": data[0], "Url": result
        //            });
        //        }
        //    })
        //}, function (error) {
        //    alert("保存失败");
        //    return;
        //});
    }
    $scope.sound = function () {
        var fjid = window.localStorage.getItem("fjid");
        if (fjid == null || fjid == undefined) {
            alert("请先选择区域");
            return;
        }
        var cssound = "cssound";
        var fj = {
            "type": 2, "data": cssound
        };
        if (fjid == "1") {
            $scope.unupload1.push(fj);
            $scope.File1.push({
                "FileGuid": 1, "FullName": cssound, "Url": "Content/img/ht.png"
            });
        } else if (fjid == "2") {
            $scope.unupload2.push(fj);
            $scope.File2.push({
                "FileGuid": 2, "FullName": cssound, "Url": "Content/img/ht.png"
            });
        } else if (fjid == "3") {
            $scope.unupload3.push(fj);
            $scope.File3.push({
                "FileGuid": 3, "FullName": cssound, "Url": "Content/img/ht.png"
            });
        } else if (fjid == "4") {
            $scope.unupload4.push(fj);
            $scope.File4.push({
                "FileGuid": 4, "FullName": cssound, "Url": "Content/img/ht.png"
            });
        } else if (fjid == "5") {
            $scope.unupload5.push(fj);
            $scope.File5.push({
                "FileGuid": 5, "FullName": cssound, "Url": "Content/img/ht.png"
            });
        } else if (fjid == "6") {
            $scope.unupload6.push(fj);
            $scope.File6.push({
                "FileGuid": 6, "FullName": cssound, "Url": "Content/img/ht.png"
            });
        } else if (fjid == "7") {
            $scope.unupload7.push(fj);
            $scope.File7.push({
                "FileGuid": 7, "FullName": cssound, "Url": "Content/img/ht.png"
            });
        } else if (fjid == "8") {
            $scope.unupload8.push(fj);
            $scope.File8.push({
                "FileGuid": 8, "FullName": cssound, "Url": "Content/img/ht.png"
            });
        } else if (fjid == "9") {
            $scope.unupload9.push(fj);
            $scope.File9.push({
                "FileGuid": 9, "FullName": cssound, "Url": "Content/img/ht.png"
            });
        } else if (fjid == "10") {
            $scope.unupload10.push(fj);
            $scope.File10.push({
                "FileGuid": 10, "FullName": cssound, "Url": "Content/img/ht.png"
            });
        } else if (fjid == "11") {
            $scope.unupload11.push(fj);
            $scope.File11.push({
                "FileGuid": 11, "FullName": cssound, "Url": "Content/img/ht.png"
            });
        } else if (fjid == "12") {
            $scope.unupload12.push(fj);
            $scope.File12.push({
                "FileGuid": 12, "FullName": cssound, "Url": "Content/img/ht.png"
            });
        }
        //RecordApp.doStartRecordApp("http://fileupload.openxt.com/ueditor/controller.ashx", -1, {
        //    action: "uploadfile"
        //}, false, function (str) {
        //    var data = JSON.parse(str);
        //    var fj = {
        //        "type": 2, "data": data[0]
        //    };
        //    var fjid = window.localStorage.getItem("fjid");
        //    if (fjid == null || fjid == undefined) {
        //        alert("请先选择区域");
        //        return;
        //    }
        //    //PreviewPictureApp.doPreviewPicture(data[0], function (success) {
        //    //    var result = "data:image/jpg;base64," + success;
        //    if (fjid == "1") {
        //        $scope.unupload1.push(fj);
        //        $scope.File1.push({
        //            "FileGuid": 1, "FullName": data[0], "Url": "Content/img/ht.png"
        //        });
        //    } else if (fjid == "2") {
        //        $scope.unupload2.push(fj);
        //        $scope.File2.push({
        //            "FileGuid": 2, "FullName": data[0], "Url": "Content/img/ht.png"
        //        });
        //    } else if (fjid == "3") {
        //        $scope.unupload3.push(fj);
        //        $scope.File3.push({
        //            "FileGuid": 3, "FullName": data[0], "Url": "Content/img/ht.png"
        //        });
        //    } else if (fjid == "4") {
        //        $scope.unupload4.push(fj);
        //        $scope.File4.push({
        //            "FileGuid": 4, "FullName": data[0], "Url": "Content/img/ht.png"
        //        });
        //    } else if (fjid == "5") {
        //        $scope.unupload5.push(fj);
        //        $scope.File5.push({
        //            "FileGuid": 5, "FullName": data[0], "Url": "Content/img/ht.png"
        //        });
        //    } else if (fjid == "6") {
        //        $scope.unupload6.push(fj);
        //        $scope.File6.push({
        //            "FileGuid": 6, "FullName": data[0], "Url": "Content/img/ht.png"
        //        });
        //    } else if (fjid == "7") {
        //        $scope.unupload7.push(fj);
        //        $scope.File7.push({
        //            "FileGuid": 7, "FullName": data[0], "Url": "Content/img/ht.png"
        //        });
        //    } else if (fjid == "8") {
        //        $scope.unupload8.push(fj);
        //        $scope.File8.push({
        //            "FileGuid": 8, "FullName": data[0], "Url": "Content/img/ht.png"
        //        });
        //    } else if (fjid == "9") {
        //        $scope.unupload9.push(fj);
        //        $scope.File9.push({
        //            "FileGuid": 9, "FullName": data[0], "Url": "Content/img/ht.png"
        //        });
        //    } else if (fjid == "10") {
        //        $scope.unupload10.push(fj);
        //        $scope.File10.push({
        //            "FileGuid": 10, "FullName": data[0], "Url": "Content/img/ht.png"
        //        });
        //    } else if (fjid == "11") {
        //        $scope.unupload11.push(fj);
        //        $scope.File11.push({
        //            "FileGuid": 11, "FullName": data[0], "Url": "Content/img/ht.png"
        //        });
        //    } else if (fjid == "12") {
        //        $scope.unupload12.push(fj);
        //        $scope.File12.push({
        //            "FileGuid": 12, "FullName": data[0], "Url": "Content/img/ht.png"
        //        });
        //    }
        //    //})
        //}, function (error) {
        //    alert("保存失败");
        //    return;
        //});
    }
    $scope.speakyy = function () {
        VoiceApp.doStartRecognizerApp(function (code) {
            var data = JSON.parse(code);
            var fjid = window.localStorage.getItem("fjid");
            $("#Rinput-" + fjid).val(code)
        })
    }
    $scope.delimg1 = function (index) {
        $scope.File1.remove(index);
        if (index >= $scope.list1) {
            $scope.unupload1.remove((index - $scope.list1 + 1));
        } else {
            $scope.list1 = $scope.list1 - 1;
        }
    }
    $scope.delimg2 = function (index) {
        $scope.File2.remove(index);
        if (index >= $scope.list2) {
            $scope.unupload2.remove((index - $scope.list2 + 1));
        } else {
            $scope.list2 = $scope.list2 - 1;
        }
    }
    $scope.delimg3 = function (index) {
        $scope.File3.remove(index);
        if (index >= $scope.list3) {
            $scope.unupload3.remove((index - $scope.list3 + 1));
        } else {
            $scope.list3 = $scope.list3 - 1;
        }
    }
    $scope.delimg4 = function (index) {
        $scope.File4.remove(index);
        if (index >= $scope.list4) {
            $scope.unupload4.remove((index - $scope.list4 + 1));
        } else {
            $scope.list4 = $scope.list4 - 1;
        }
    }
    $scope.delimg5 = function (index) {
        $scope.File5.remove(index);
        if (index >= $scope.list5) {
            $scope.unupload5.remove((index - $scope.list5 + 1));
        } else {
            $scope.list5 = $scope.list5 - 1;
        }
    }
    $scope.delimg6 = function (index) {
        $scope.File6.remove(index);
        if (index >= $scope.list6) {
            $scope.unupload6.remove((index - $scope.list6 + 1));
        } else {
            $scope.list6 = $scope.list6 - 1;
        }
    }
    $scope.delimg7 = function (index) {
        $scope.File7.remove(index);
        if (index >= $scope.list7) {
            $scope.unupload7.remove((index - $scope.list7 + 1));
        } else {
            $scope.list7 = $scope.list7 - 1;
        }
    }
    $scope.delimg8 = function (index) {
        $scope.File8.remove(index);
        if (index >= $scope.list8) {
            $scope.unupload8.remove((index - $scope.list8 + 1));
        } else {
            $scope.list8 = $scope.list8 - 1;
        }
    }
    $scope.delimg9 = function (index) {
        $scope.File9.remove(index);
        if (index >= $scope.list9) {
            $scope.unupload9.remove((index - $scope.list9 + 1));
        } else {
            $scope.list9 = $scope.list9 - 1;
        }
    }
    $scope.delimg10 = function (index) {
        $scope.File10.remove(index);
        if (index >= $scope.list10) {
            $scope.unupload10.remove((index - $scope.list10 + 1));
        } else {
            $scope.list10 = $scope.list10 - 1;
        }
    }
    $scope.delimg11 = function (index) {
        $scope.File11.remove(index);
        if (index >= $scope.list11) {
            $scope.unupload11.remove((index - $scope.list11 + 1));
        } else {
            $scope.list11 = $scope.list11 - 1;
        }
    }
    $scope.delimg12 = function (index) {
        $scope.File12.remove(index);
        if (index >= $scope.list12) {
            $scope.unupload12.remove((index - $scope.list12 + 1));
        } else {
            $scope.list12 = $scope.list12 - 1;
        }
    }
    $scope.next1 = function () {
        var btime = document.getElementById("DecorationStart").value;
        if (btime == "" || btime == null) {
            alert("装修开始时间不能为空");
            return;
        }
        var etime = document.getElementById("DecorationEnd").value;
        if (etime == "" || etime == null) {
            alert("装修结束时间不能为空");
            return;
        }
        if ($scope.Recorder == null || $scope.Recorder == undefined) {
            alert("备案人名称不能为空");
            return;
        }
        if (!/^1[3|4|5|7|8]\d{9}$/.test($scope.RecorderTel)) {
            alert("备案人手机号格式错误");
            return;
        }
        if (!/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test($scope.RecorderIDCard)) {
            alert("备案人身份证格式错误");
            return;
        }
        if ($scope.RecorderAddress == null || $scope.RecorderAddress == undefined) {
            alert("备案人现详细住址不能为空");
            return;
        }
        $(".page1").hide();
        $(".page2").show();
    }
    $scope.next2 = function () {
        if ($scope.qx == "" || $scope.qx == null) {
            alert("请选择区县");
            return;
        }
        if ($scope.jd == "" || $scope.jd == null) {
            alert("请选择街道");
            return;
        }
        if ($scope.sq == "" || $scope.sq == null) {
            alert("请选择社区");
            return;
        }
        if ($scope.xm == "" || $scope.xm == null) {
            alert("请选择项目");
            return;
        }
        if ($scope.zh == "" || $scope.zh == null) {
            alert("请选择幢序号");
            return;
        }
        if ($scope.dy == "" || $scope.dy == null) {
            alert("请选择单元");
            return;
        }
        if ($scope.hu == "" || $scope.hu == null) {
            alert("请选择户号");
            return;
        }
        $(".page2").hide();
        $(".page3").show();
    }
    $scope.next3 = function () {
        var CertificateNo = document.getElementById("CertificateNo").value;
        if (CertificateNo == "" || CertificateNo == null) {
            alert("产权证号不能为空");
            return;
        }
        if (isNaN(CertificateNo)) {
            alert("产权证号格式错误");
            return;
        }
        if (CertificateNo < 0) {
            alert("产权证号不能为负数");
            return;
        }
        var CertificateJZMJ = document.getElementById("CertificateJZMJ").value;
        if (CertificateJZMJ == "" || CertificateJZMJ == null) {
            alert("产权证建筑面积不能为空");
            return;
        }
        if (isNaN(CertificateJZMJ)) {
            alert("产权证建筑面积格式错误");
            return;
        }
        if (CertificateJZMJ < 0) {
            alert("产权证建筑面积不能为负数");
            return;
        }
        var CertificateAddress = document.getElementById("CertificateAddress").value;
        if (CertificateAddress == "" || CertificateAddress == null) {
            alert("产权证地址不能为空");
            return;
        }
        var HouseChen = document.getElementById("HouseChen").value;
        if (HouseChen == "" || HouseChen == null) {
            alert("房屋总层数不能为空");
            return;
        }
        if (isNaN(HouseChen)) {
            alert("房屋总层数格式错误");
            return;
        }
        for (var i = 0; i < $scope.HouseOwners.length; i++) {
            if ($scope.HouseOwners[i].Name == "" || $scope.HouseOwners[i].Name == null) {
                alert("产权人信息未保存,请先保存!");
                return;
            }
        }
        $(".page3").hide();
        $(".page4").show();
    }
    $scope.next4 = function () {
        var DecoratorType = $scope.DecoratorType;
        if (DecoratorType == 23263) {
            var DecorationPerson = document.getElementById("DecorationPerson").value;
            if (DecorationPerson == "" || DecorationPerson == null) {
                alert("负责人名字不能为空");
                return;
            }
            var DecorationPersonTel = document.getElementById("DecorationPersonTel").value;
            if (DecorationPersonTel == "" || DecorationPersonTel == null) {
                alert("联系电话不能为空");
                return;
            }
            if (!/^1[3|4|5|7|8]\d{9}$/.test($scope.DecorationPersonTel)) {
                alert("联系电话格式错误");
                return;
            }
        } else if (DecoratorType == 23264) {
            var DecorationUnit = document.getElementById("DecorationUnit").value;
            if (DecorationUnit == "" || DecorationUnit == null) {
                alert("装饰装修公司全称不能为空");
                return;
            }
            var ProjectManager = document.getElementById("ProjectManager").value;
            if (ProjectManager == "" || ProjectManager == null) {
                alert("项目经理名称不能为空");
                return;
            }
            var ProjectManagerTel = document.getElementById("ProjectManagerTel").value;
            if (ProjectManagerTel == "" || ProjectManagerTel == null) {
                alert("项目经理电话不能为空");
                return;
            }
            if (!/^1[3|4|5|7|8]\d{9}$/.test($scope.ProjectManagerTel)) {
                alert("联系电话格式错误");
                return;
            }
        }
        $(".page4").hide();
        $(".page5").show();
    }
    $scope.next5 = function () {
        if (typeof ($scope.File1) === "object" && $scope.File1.length > 0) {
        } else {
            alert("请上传产权证或购房合同资料");
            return;
        }
        if (typeof ($scope.File2) === "object" && $scope.File2.length > 0) {
        } else {
            alert("请上传产权人身份证资料");
            return;
        }
        if (typeof ($scope.File3) === "object" && $scope.File3.length > 0) {
        } else {
            alert("请上传备案人身份证资料");
            return;
        }
        if (typeof ($scope.File4) === "object" && $scope.File4.length > 0) {
        } else {
            alert("请上传装修设计图纸或施工方案资料");
            return;
        }
        if (typeof ($scope.File5) === "object" && $scope.File5.length > 0) {
            $("#input-5").addClass("checked");
        }
        if (typeof ($scope.File6) === "object" && $scope.File6.length > 0) {
            $("#input-6").addClass("checked");
        }
        if (typeof ($scope.File7) === "object" && $scope.File7.length > 0) {
            $("#input-7").addClass("checked");
        }
        if (typeof ($scope.File8) === "object" && $scope.File8.length > 0) {
            $("#input-8").addClass("checked");
        }
        if (typeof ($scope.File9) === "object" && $scope.File9.length > 0) {
            $("#input-9").addClass("checked");
        }
        if (typeof ($scope.File10) === "object" && $scope.File10.length > 0) {
            $("#input-10").addClass("checked");
        }
        if (typeof ($scope.File11) === "object" && $scope.File11.length > 0) {
            $("#input-11").addClass("checked");
        }
        if (typeof ($scope.File12) === "object" && $scope.File12.length > 0) {
            $("#input-12").addClass("checked");
        }
        $(".page5").hide();
        $(".page6").show();
    }
    $scope.next6 = function () {
        for (var i = 0; i < $scope.balx.length; i++) {
            if ($scope.balx[i].CODEID == $scope.RecorderType) $scope.RecorderType2 = $scope.balx[i].CODENAME;
        }
        $scope.DecorationStart = document.getElementById("DecorationStart").value;
        $scope.DecorationEnd = document.getElementById("DecorationEnd").value;
        $scope.RecordDate = document.getElementById("RecordDate").value;
        //for (var i = 0; i < $scope.quxian.length; i++) {
        //    if ($scope.quxian[i].CODEID == $scope.qx) $scope.qxname = $scope.quxian[i].CODENAME;
        //}
        //for (var i = 0; i < $scope.street.length; i++) {
        //    if ($scope.street[i].CODEID == $scope.jd) $scope.jdname = $scope.street[i].CODENAME;
        //}
        //for (var i = 0; i < $scope.block.length; i++) {
        //    if ($scope.block[i].CODEID == $scope.sq) $scope.sqname = $scope.block[i].CODENAME;
        //}
        //for (var i = 0; i < $scope.item.length; i++) {
        //    if ($scope.item[i].CODEID == $scope.xm) $scope.xmname = $scope.item[i].CODENAME;
        //}
        //for (var i = 0; i < $scope.zhuang.length; i++) {
        //    if ($scope.zhuang[i].HOUSEID == $scope.zh) $scope.zhname = $scope.zhuang[i].ADDRESS;
        //}
        //for (var i = 0; i < $scope.single.length; i++) {
        //    if ($scope.single[i].ID == $scope.dy) $scope.dyname = $scope.single[i].NAME;
        //}
        //for (var i = 0; i < $scope.huhao.length; i++) {
        //    if ($scope.huhao[i].ID == $scope.hu) $scope.huname = $scope.huhao[i].HUNO;
        //}
        //for (var i = 0; i < $scope.house.length; i++) {
        //    if ($scope.house[i].CODEID == $scope.HouseNature) $scope.HouseNature2 = $scope.house[i].CODENAME;
        //}
        //for (var i = 0; i < $scope.zhuangx.length; i++) {
        //    if ($scope.zhuangx[i].CODEID == $scope.DecoratorType) $scope.DecoratorType2 = $scope.zhuangx[i].CODENAME;
        //}
        var File = new Array();
        if (typeof ($scope.File1) === "object" && $scope.File1.length > 0) {
            File = File.concat($scope.File1);
        }
        if (typeof ($scope.File2) === "object" && $scope.File2.length > 0) {
            File = File.concat($scope.File2);
        }
        if (typeof ($scope.File3) === "object" && $scope.File3.length > 0) {
            File = File.concat($scope.File3);
        }
        if (typeof ($scope.File4) === "object" && $scope.File4.length > 0) {
            File = File.concat($scope.File4);
        }
        if (typeof ($scope.File5) === "object" && $scope.File5.length > 0) {
            File = File.concat($scope.File5);
        }
        if (typeof ($scope.File6) === "object" && $scope.File6.length > 0) {
            File = File.concat($scope.File6);
        }
        if (typeof ($scope.File7) === "object" && $scope.File7.length > 0) {
            File = File.concat($scope.File7);
        }
        if (typeof ($scope.File8) === "object" && $scope.File8.length > 0) {
            File = File.concat($scope.File8);
        }
        if (typeof ($scope.File9) === "object" && $scope.File9.length > 0) {
            File = File.concat($scope.File9);
        }
        if (typeof ($scope.File10) === "object" && $scope.File10.length > 0) {
            File = File.concat($scope.File10);
        }
        if (typeof ($scope.File11) === "object" && $scope.File11.length > 0) {
            File = File.concat($scope.File11);
        }
        if (typeof ($scope.File12) === "object" && $scope.File12.length > 0) {
            File = File.concat($scope.File12);
        }
        $scope.allFile = File;
        $(".page6").hide();
        $(".page7").show();
    }
    $scope.next7 = function () {
        var dtime = document.getElementById("RecordDate").value;
        if (dtime == "" || dtime == null) {
            alert("备案时间不能为空");
            return;
        }
        $(".page7").hide();
        $(".page8").show();
    }
    $scope.lxsub = function () {
        var user = window.localStorage.getItem("User");
        var lixian = {
        };
        lixian.PDRID = $routeParams.id;
        lixian.DHID = null;
        lixian.qxid = $scope.qx;
        lixian.jdid = $scope.jd;
        lixian.sqid = $scope.sq;
        lixian.xmid = $scope.xm;
        lixian.zhid = $scope.zh;
        lixian.dyid = $scope.dy;
        lixian.ucHuSelected_LPB = $scope.hu;
        //lixian.Attachments = $scope.allAttachments;
        lixian.txtCertificateAddress = $scope.CertificateAddress;
        lixian.txtCertificateJZMJ = $scope.CertificateJZMJ;
        lixian.txtCertificateNo = $scope.CertificateNo;
        lixian.txtDecorationEnd = $scope.DecorationEnd;
        lixian.txtDecorationStart = $scope.DecorationStart;
        if ($scope.DecoratorType == 23263) {
            lixian.rbUnit = false;
            lixian.hidUnit = "";
            lixian.hidPerson = $scope.DecoratorType;
            lixian.txtDecorationPerson = $scope.DecorationPerson;
            lixian.txtDecorationPersonTel = $scope.DecorationPersonTel;
            lixian.txtDecorationUnit = "";
            lixian.txtProjectManager = "";
            lixian.txtProjectManagerTel = "";
        } else if ($scope.DecoratorType == 23264) {
            lixian.rbUnit = true;
            lixian.hidUnit = $scope.DecoratorType;
            lixian.hidPerson = "";
            lixian.txtDecorationPerson = "";
            lixian.txtDecorationPersonTel = "";
            lixian.txtDecorationUnit = $scope.DecorationUnit;
            lixian.txtProjectManager = $scope.ProjectManager;
            lixian.txtProjectManagerTel = $scope.ProjectManagerTel;
        }
        lixian.txtHouseChen = $scope.HouseChen;
        lixian.rblHouseNature = $scope.HouseNature;
        lixian.HouseOwnerList = $scope.HouseOwners;
        lixian.from = "";
        lixian.rblZZFZZ = "";
        lixian.rbZhuangNew = $scope.IsZhuangNew;
        lixian.txtRecordDate = $scope.RecordDate;
        lixian.txtRecorder = $scope.Recorder;
        lixian.txtRecorderAddress = $scope.RecorderAddress;
        lixian.txtRecorderIDCard = $scope.RecorderIDCard;
        lixian.txtRecorderTel = Number($scope.RecorderTel);
        lixian.rblRecorderType = $scope.RecorderType;
        lixian.UserDepartmentID = $scope.UserDepartmentID;
        lixian.File1 = $scope.File1;
        lixian.File2 = $scope.File2;
        lixian.File3 = $scope.File3;
        lixian.File4 = $scope.File4;
        lixian.File5 = $scope.File5;
        lixian.File6 = $scope.File6;
        lixian.File7 = $scope.File7;
        lixian.File8 = $scope.File8;
        lixian.File9 = $scope.File9;
        lixian.File10 = $scope.File10;
        lixian.File11 = $scope.File11;
        lixian.File12 = $scope.File12;
        var lixian2 = JSON.stringify(lixian);
        window.localStorage.setItem("zxba" + $routeParams.id, lixian2);
        var unupload3 = new Array();
        if (typeof ($scope.unupload1) === "object" && $scope.unupload1.length > 0) {
            unupload3 = unupload3.concat($scope.unupload1);
            $scope.unupload1 = null;
        }
        if (typeof ($scope.unupload2) === "object" && $scope.unupload2.length > 0) {
            unupload3 = unupload3.concat($scope.unupload2);
            $scope.unupload2 = null;
        }
        if (typeof ($scope.unupload3) === "object" && $scope.unupload3.length > 0) {
            unupload3 = unupload3.concat($scope.unupload3);
            $scope.unupload3 = null;
        }
        if (typeof ($scope.unupload4) === "object" && $scope.unupload4.length > 0) {
            unupload3 = unupload3.concat($scope.unupload4);
            $scope.unupload4 = null;
        }
        if (typeof ($scope.unupload5) === "object" && $scope.unupload5.length > 0) {
            unupload3 = unupload3.concat($scope.unupload5);
            $scope.unupload5 = null;
        }
        if (typeof ($scope.unupload6) === "object" && $scope.unupload6.length > 0) {
            unupload3 = unupload3.concat($scope.unupload6);
            $scope.unupload6 = null;
        }
        if (typeof ($scope.unupload7) === "object" && $scope.unupload7.length > 0) {
            unupload3 = unupload3.concat($scope.unupload7);
            $scope.unupload7 = null;
        }
        if (typeof ($scope.unupload8) === "object" && $scope.unupload8.length > 0) {
            unupload3 = unupload3.concat($scope.unupload8);
            $scope.unupload8 = null;
        }
        if (typeof ($scope.unupload9) === "object" && $scope.unupload9.length > 0) {
            unupload3 = unupload3.concat($scope.unupload9);
            $scope.unupload9 = null;
        }
        if (typeof ($scope.unupload10) === "object" && $scope.unupload10.length > 0) {
            unupload3 = unupload3.concat($scope.unupload10);
            $scope.unupload10 = null;
        }
        if (typeof ($scope.unupload11) === "object" && $scope.unupload11.length > 0) {
            unupload3 = unupload3.concat($scope.unupload11);
            $scope.unupload11 = null;
        }
        if (typeof ($scope.unupload12) === "object" && $scope.unupload12.length > 0) {
            unupload3 = unupload3.concat($scope.unupload12);
            $scope.unupload12 = null;
        }
        var unupload2 = JSON.stringify(unupload3);
        window.localStorage.setItem("zxba" + $routeParams.id + "unupload", unupload2);
        alert("离线保存成功")
        $location.path("/decolog")
    }
    $scope.zxsub = function () {
        {
            var unupload3 = new Array();
            var unupload = new Array();
            if (typeof ($scope.unupload1) === "object" && $scope.unupload1.length > 0) {
                unupload3 = unupload3.concat($scope.unupload1);
                $scope.unupload1 = null;
            }
            if (typeof ($scope.unupload2) === "object" && $scope.unupload2.length > 0) {
                unupload3 = unupload3.concat($scope.unupload2);
                $scope.unupload2 = null;
            }
            if (typeof ($scope.unupload3) === "object" && $scope.unupload3.length > 0) {
                unupload3 = unupload3.concat($scope.unupload3);
                $scope.unupload3 = null;
            }
            if (typeof ($scope.unupload4) === "object" && $scope.unupload4.length > 0) {
                unupload3 = unupload3.concat($scope.unupload4);
                $scope.unupload4 = null;
            }
            if (typeof ($scope.unupload5) === "object" && $scope.unupload5.length > 0) {
                unupload3 = unupload3.concat($scope.unupload5);
                $scope.unupload5 = null;
            }
            if (typeof ($scope.unupload6) === "object" && $scope.unupload6.length > 0) {
                unupload3 = unupload3.concat($scope.unupload6);
                $scope.unupload6 = null;
            }
            if (typeof ($scope.unupload7) === "object" && $scope.unupload7.length > 0) {
                unupload3 = unupload3.concat($scope.unupload7);
                $scope.unupload7 = null;
            }
            if (typeof ($scope.unupload8) === "object" && $scope.unupload8.length > 0) {
                unupload3 = unupload3.concat($scope.unupload8);
                $scope.unupload8 = null;
            }
            if (typeof ($scope.unupload9) === "object" && $scope.unupload9.length > 0) {
                unupload3 = unupload3.concat($scope.unupload9);
                $scope.unupload9 = null;
            }
            if (typeof ($scope.unupload10) === "object" && $scope.unupload10.length > 0) {
                unupload3 = unupload3.concat($scope.unupload10);
                $scope.unupload10 = null;
            }
            if (typeof ($scope.unupload11) === "object" && $scope.unupload11.length > 0) {
                unupload3 = unupload3.concat($scope.unupload11);
                $scope.unupload11 = null;
            }
            if (typeof ($scope.unupload12) === "object" && $scope.unupload12.length > 0) {
                unupload3 = unupload3.concat($scope.unupload12);
                $scope.unupload12 = null;
            }
            var uploaded = window.localStorage.getItem("zxba" + $routeParams.id + "uploaded");
            var unupload2 = window.localStorage.getItem("zxba" + $routeParams.id + "unupload");
            if (uploaded != null && uploaded != undefined) {
                var unupload = JSON.parse(unupload2);
            } else if (unupload2 != null && unupload2 != undefined) {
                var unupload = JSON.parse(unupload2);
            } else {
                var unupload = unupload3;
            }
            var unuploadlen = unupload.length;
            if (unupload.length > 0) {
                for (var i = 0; i < unuploadlen; i++) {
                    FileUploadApp.doInstantFileUploadApp("http://fileupload.openxt.com/ueditor/controller.ashx", {
                        action: "uploadfile"
                    }, unupload[i].data, function (str) {
                        var result = JSON.parse(str);
                        alert(unupload.data + "上传成功");
                        uploaded.push(unupload[i]);
                        window.localStorage.setItem("zxba" + $routeParams.id + "uploaded", uploaded);
                        unupload.remove(i);
                        window.localStorage.setItem("zxba" + $routeParams.id + "unupload", unupload);
                        for (var j = 0; j < $scope.allFile.length; j++) {
                            if ($scope.allFile[j].FileTitle == unupload[i].data) {
                                $scope.allFile[j].FileUrl = result["prefix"] + result["url"];
                            }
                        }
                        if (unupload.length == 0) {
                            var user = window.localStorage.getItem("User");
                            var zaixian = {
                            };
                            zaixian.Attachments = $scope.allAttachments;
                            zaixian.CertificateAddress = $scope.CertificateAddress;
                            zaixian.CertificateJZMJ = $scope.CertificateJZMJ;
                            zaixian.CertificateNo = $scope.CertificateNo;
                            zaixian.CreateID = user;
                            zaixian.DHID = -1;
                            zaixian.DecorationEnd = $scope.DecorationEnd;
                            zaixian.DecorationStart = $scope.DecorationStart;
                            zaixian.DecoratorType = $scope.DecoratorType;
                            if ($scope.DecoratorType == 23263) {
                                zaixian.DecorationPerson = $scope.DecorationPerson;
                                zaixian.DecorationPersonTel = $scope.DecorationPersonTel;
                                zaixian.DecorationUnit = "";
                                zaixian.ProjectManager = "";
                                zaixian.ProjectManagerTel = "";
                            } else if ($scope.DecoratorType == 23264) {
                                zaixian.DecorationPerson = "";
                                zaixian.DecorationPersonTel = "";
                                zaixian.DecorationUnit = $scope.DecorationUnit;
                                zaixian.ProjectManager = $scope.ProjectManager;
                                zaixian.ProjectManagerTel = $scope.ProjectManagerTel;
                            }
                            zaixian.HouseChen = $scope.HouseChen;
                            zaixian.HouseNature = $scope.HouseNature;
                            zaixian.HouseOwners = $scope.HouseOwners;
                            zaixian.HuID = $scope.hu;
                            zaixian.IsZZ = $scope.IsZZ;
                            zaixian.IsZhuangNew = $scope.IsZhuangNew;
                            zaixian.RecordDate = $scope.RecordDate;
                            zaixian.Recorder = $scope.Recorder;
                            zaixian.RecorderAddress = $scope.RecorderAddress;
                            zaixian.RecorderIDCard = $scope.RecorderIDCard;
                            zaixian.RecorderTel = $scope.RecorderTel;
                            zaixian.RecorderType = $scope.RecorderType;
                            zaixian.UserDepartmentID = $scope.UserDepartmentID;
                            var zaixian2 = JSON.stringify(zaixian);
                            $http.post(sytdapp.APIHOST + "Housing/AddHousingFull?cid=" + user, { models: zaixian2 }).success(function (data) {
                                if (data.level == 0) {
                                    alert("在线提交成功!")
                                    window.localStorage.removeItem("zxba" + $routeParams.id);
                                    window.localStorage.removeItem("zxba" + $routeParams.id + "uploaded");
                                    window.localStorage.removeItem("zxba" + $routeParams.id + "unupload");
                                    $location.path("/decolog")
                                } else {
                                    alert("在线提交失败!")
                                }
                            }).error(function (data, status, headers, config) {
                                alert("网络不通/服务停止");
                                $location.path("/");
                            });
                        }
                    }, function (error) {
                        alert("上传失败!请再次提交，重新上传" + error);
                        return;
                    });
                }
            } else {
                var user = window.localStorage.getItem("User");
                var zaixian = {
                };
                zaixian.PDRID = $routeParams.id;
                zaixian.DHID = null;
                zaixian.ucHuSelected_LPB = $scope.hu;
                //zaixian.Attachments = $scope.allAttachments;
                zaixian.txtCertificateAddress = $scope.CertificateAddress;
                zaixian.txtCertificateJZMJ = $scope.CertificateJZMJ;
                zaixian.txtCertificateNo = $scope.CertificateNo;
                //zaixian.CreateID = user;

                zaixian.txtDecorationEnd = $scope.DecorationEnd;
                zaixian.txtDecorationStart = $scope.DecorationStart;
                //zaixian.DecoratorType = $scope.DecoratorType;
                if ($scope.DecoratorType == 23263) {
                    zaixian.rbUnit = false;
                    zaixian.hidUnit = "";
                    zaixian.hidPerson = $scope.DecoratorType;
                    zaixian.txtDecorationPerson = $scope.DecorationPerson;
                    zaixian.txtDecorationPersonTel = $scope.DecorationPersonTel;
                    zaixian.txtDecorationUnit = "";
                    zaixian.txtProjectManager = "";
                    zaixian.txtProjectManagerTel = "";
                } else if ($scope.DecoratorType == 23264) {
                    zaixian.rbUnit = true;
                    zaixian.hidUnit = $scope.DecoratorType;
                    zaixian.hidPerson = "";
                    zaixian.txtDecorationPerson = "";
                    zaixian.txtDecorationPersonTel = "";
                    zaixian.txtDecorationUnit = $scope.DecorationUnit;
                    zaixian.txtProjectManager = $scope.ProjectManager;
                    zaixian.txtProjectManagerTel = $scope.ProjectManagerTel;
                }
                zaixian.txtHouseChen = $scope.HouseChen;
                zaixian.rblHouseNature = $scope.HouseNature;
                zaixian.HouseOwnerList = $scope.HouseOwners;

                //zaixian.IsZZ = $scope.IsZZ;
                zaixian.rbZhuangNew = $scope.IsZhuangNew;
                zaixian.txtRecordDate = $scope.RecordDate;
                zaixian.txtRecorder = $scope.Recorder;
                zaixian.txtRecorderAddress = $scope.RecorderAddress;
                zaixian.txtRecorderIDCard = $scope.RecorderIDCard;
                zaixian.txtRecorderTel = Number($scope.RecorderTel);
                zaixian.rblRecorderType = $scope.RecorderType;
                zaixian.UserDepartmentID = $scope.UserDepartmentID;
                //zaixian.
                var zaixian2 = JSON.stringify(zaixian);
                fac.get("登记备案详细", "Housing/AddHousingFull", function (data) {
                    if (data.level == 0) {
                        alert("在线提交成功!")
                        window.localStorage.removeItem("zxba" + $routeParams.id);
                        window.localStorage.removeItem("zxba" + $routeParams.id + "uploaded");
                        window.localStorage.removeItem("zxba" + $routeParams.id + "unupload");
                        $location.path("/decolog")
                    } else {
                        alert("在线提交失败!")
                    }
                }, {
                    data: {
                        models: zaixian2
                    }
                });
            }
        }
    }
}]);
//进度查询
app.controller("DecoRateController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {

    //fac.accessStatistics("#/decorate");
    //$scope.back = function () {
    //    $location.path("/deco");
    //}
    $scope.page = 1;
    $scope.rows = 10;
    fac.get("进度", "Housing/GetBeiAnRate?pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
        for (var i = 0; i < data.value.length; i++) {
            if (data.value[i].STATUS == 0) {
                data.value[i].STATUSNAME = "未受理"
            } else {
                data.value[i].STATUSNAME = "已受理"
            }
        }
        $scope.list = data.value;
    });
    $scope.getdata = function () {
        $scope.page++;
        fac.get("进度", "Housing/GetBeiAnRate?pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            for (var i = 0; i < data.value.length; i++) {
                if (data.value[i].STATUS == 0) {
                    data.value[i].STATUSNAME = "未受理"
                } else {
                    data.value[i].STATUSNAME = "已受理"
                }
            }
            $scope.list = $scope.list.concat(data.value);
        });
    }
}]);
//巡查任务列表
app.controller("PatrolTaskController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {

    //fac.accessStatistics("#/patroltask");
    //$scope.back = function () {
    //    $location.path("/patrol");
    //}
    $scope.page = 1;
    $scope.rows = 10;
    $scope.page2 = 1;
    $scope.rows2 = 10;
    var customerid = window.localStorage.getItem("User");
    var patroltaskid = window.localStorage.getItem("Patroltaskid");
    if (patroltaskid == null || patroltaskid == undefined) patroltaskid = "";
    //待处理
    fac.get("巡查任务待处理", "HousePatrol/GetMission?missioncode=&missiontype=" + 0 + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows + "&houseid=", function (data) {
        $scope.list = data.value;
    });
    //已处理
    fac.get("巡查任务已处理", "HousePatrol/GetMission?missioncode=&missiontype=" + 1 + "&pageIndex=" + $scope.page2 + "&pageSize=" + $scope.rows2 + "&houseid=", function (data) {
        $scope.list2 = data.value;
    });
    $scope.getdata = function () {
        $scope.page++;
        var patroltaskid = window.localStorage.getItem("Patroltaskid");
        if (patroltaskid == null) patroltaskid = "";
        fac.get("巡查任务待处理", "HousePatrol/GetMission?missioncode=&missiontype=" + 0 + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows + "&houseid=" + patroltaskid, function (data) {
            $scope.list = $scope.list.concat(data.value);
        });
    }
    $scope.getdata2 = function () {
        $scope.page2++;
        var patroltaskid = window.localStorage.getItem("Patroltaskid");
        if (patroltaskid == null) patroltaskid = "";
        fac.get("巡查任务已处理", "HousePatrol/GetMission?missioncode=&missiontype=" + 1 + "&pageIndex=" + $scope.page2 + "&pageSize=" + $scope.rows2 + "&houseid=" + patroltaskid, function (data) {
            $scope.list2 = $scope.list.concat(data.value);
        });
    }
    //$scope.find = function () {
    //    if ($scope.name == "") {
    //        alert("请输入房屋编码");
    //        return;
    //    }
    //    window.localStorage.setItem("Patroltaskid", $scope.name);
    //    if ($(".fl_active td:eq(0) .active").html() == undefined) {
    //        $scope.page2 = 1;
    //        $scope.rows2 = 10;
    //        $http.get(sytdapp.APPHOST+"HousePatrol/GetMission?missioncode=&customerid=" + customerid + "&missiontype=" + 1 + "&pageIndex=" + $scope.page2 + "&pageSize=" + $scope.rows2 + "&houseid=" + $scope.name).success(function (data) {
    //            $scope.list2 = data.value;
    //        }).error(function (data, status, headers, config) {
    //            alert("网络不通/服务停止");
    //            $location.path("/");
    //        });
    //    } else {
    //        $scope.page = 1;
    //        $scope.rows = 10;
    //        $http.get(sytdapp.APPHOST+"HousePatrol/GetMission?missioncode=&customerid=" + customerid + "&missiontype=" + 0 + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows + "&houseid=" + $scope.name).success(function (data) {
    //            $scope.list = data.value;
    //        }).error(function (data, status, headers, config) {
    //            alert("网络不通/服务停止");
    //            $location.path("/");
    //        });
    //    }
    //}
    $scope.saoma = function () {
        QrcodeApp.doQrcodeApp(function (code) {
            fac.get("巡查任务？房屋", "HousePatrol/GetHouseidByDecode?decode=" + code, function (data) {
                window.localStorage.setItem("Patroltaskid", data.value);
            });
            //code为房屋ID，根据房屋ID和用户ID来精确获得任务列表
            var code1 = window.localStorage.getItem("Patroltaskid")
            $scope.page2 = 1;
            $scope.rows2 = 10;
            $scope.page = 1;
            $scope.rows = 10;
            fac.get("巡查任务待处理", "HousePatrol/GetMission?missioncode=&missiontype=" + 0 + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows + "&houseid=" + code1, function (data) {
                $scope.list = data.value;
            });
            //已处理
            fac.get("巡查任务已处理", "HousePatrol/GetMission?missioncode=&missiontype=" + 1 + "&pageIndex=" + $scope.page2 + "&pageSize=" + $scope.rows2 + "&houseid=" + code1, function (data) {
                $scope.list2 = data.value;
            });
        });
    }
    $scope.newtask = function () {
        var patroltaskid = window.localStorage.getItem("Patroltaskid");
        if (patroltaskid == null || patroltaskid == undefined) {
            $location.path("/patrolnew/");
        } else {
            fac.get("新建巡查任务", "HousePatrol/AddMission?houseid=" + patroltaskid, function (data) {
                var id = data.value.ID;
                $location.path("/patroltaskd/" + id);
            });
        }
    }
    $scope.log = function (id) {
        $location.path("/patroltaskd/" + id);
    }
}]);
//新建任务
app.controller("PatrolNewController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {

    //fac.accessStatistics("#/patrolnew");
    //$scope.back = function () {
    //    $location.path("/patroltask");
    //}
    fac.get("区县", "RecordPoint/GetArea?id=&codetypeid=", function (data) {
        $scope.quxian = data;
    });
    $scope.street = null;
    $scope.block = null;
    $scope.item = null;
    $scope.zhuang = null;
    $scope.getstreet = function (qu) {
        if (qu == null) {
            $scope.street = null;
            $scope.block = null;
            $scope.item = null;
            $scope.zhuang = null;
            $scope.single = null;
            $scope.huhao = null;
        } else {
            fac.get("街道", "RecordPoint/GetArea?id=" + qu + "&codetypeid=" + 3, function (data2) {
                $scope.street = data2;
            });
        }
    }
    $scope.getblock = function (street) {
        if (street == null) {
            $scope.block = null;
            $scope.item = null;
            $scope.zhuang = null;
            $scope.single = null;
            $scope.huhao = null;
        } else {
            fac.get("社区", "RecordPoint/GetArea?id=" + street + "&codetypeid=" + 4, function (data3) {
                $scope.block = data3;
            });
        }
    }
    $scope.getitem = function (block) {
        if (block == null) {
            $scope.item = null;
            $scope.zhuang = null;
            $scope.single = null;
            $scope.huhao = null;
        } else {
            fac.get("项目", "RecordPoint/GetArea?id=" + block + "&codetypeid=" + 21, function (data4) {
                $scope.item = data4;
            });
        }
    }
    $scope.getzhuang = function (item) {
        if (item == null) {
            $scope.zhuang = null;
            $scope.single = null;
            $scope.huhao = null;
        } else {
            fac.get("幢", "Housing/GetMoreByProjectCodeID?quxian=" + $scope.qx + "&street=" + $scope.jd + "&block=" + $scope.sq + "&projectCodeid=" + item, function (data5) {
                var result = data5.value;
                for (var i = 0; i < result.length; i++) {
                    if (result[i].Address != null) {
                        result[i].Address = result[i].Address.replace(/[#]/g, "");
                        result[i].Address = result[i].Address.replace(/[$]/g, "");
                    }
                }
                $scope.zhuang = result;
            });
        }
    }
    $scope.sure = function () {
        if ($scope.qx == "" || $scope.qx == null || $scope.qx == undefined) {
            alert("请选择区县");
            return;
        }
        if ($scope.jd == "" || $scope.jd == null || $scope.qx == undefined) {
            alert("请选择街道");
            return;
        }
        if ($scope.sq == "" || $scope.sq == null || $scope.qx == undefined) {
            alert("请选择社区");
            return;
        }
        if ($scope.xm == "" || $scope.xm == null || $scope.qx == undefined) {
            alert("请选择项目");
            return;
        }
        if ($scope.zh == "" || $scope.zh == null || $scope.qx == undefined) {
            alert("请选择幢序号");
            return;
        }
        fac.get("新增巡查任务", "HousePatrol/AddMission?houseid=" + $scope.zh, function (data) {
            var id = data.value.ID;
            $location.path("/patroltaskd/" + id);
        });
    }
}]);
//巡查任务登记
app.controller("PatrolTaskDController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {

    //fac.accessStatistics("#/patroltaskd");
    $scope.back = function () {
        if ($("[class^='page']:visible").index() == 1) {
            var lixian = window.localStorage.getItem($scope.info["MissionCode"]);
            var unupload = window.localStorage.getItem($scope.info["MissionCode"] + "unupload");
            if ((lixian == undefined || lixian == null) && (unupload == undefined || unupload == null)) {
                //$location.path("/patroltask")
                fac.trackRecord.back($location);
            } else {
                //$location.path("/patroltask")
                if (confirm("尚未离线保存,确认退出？")) {
                    //$location.path("/patroltask")
                    fac.trackRecord.back($location);
                }
            }
        } else {
            $("[class^='page']:visible").hide().prev().show();
        }
    }
    fac.get("综合等级", "HousePatrol/GetZHDJ", function (data) {
        $scope.zonghe = data;
    });
    fac.get("相邻倾斜", "HousePatrol/GetXLSG", function (data) {
        $scope.xiang = data;
    });
    fac.get("损坏等级", "HousePatrol/GetSHDJ", function (data) {
        $scope.sunhuai = data;
    });
    fac.get("巡查任务单个", "HousePatrol/Get?id=" + $routeParams.id, function (data) {
        $scope.info = data;
        var lixian = window.localStorage.getItem($scope.info["MissionCode"]);
        if (lixian == undefined || lixian == null) {
            fac.get("巡查任务单个详细", "HousePatrol/GetSingle?taskid=" + $routeParams.id, function (data) {
                $scope.olddata = data.value;
                $scope.OptionsList = data.value.OptionsList;
                $scope.NewOptionsList = {
                };
                $scope.NewOptionsList1 = {
                };
                $scope.NewOptionsList2 = {
                };
                $scope.Attachments1 = new Array();
                $scope.Attachments2 = new Array();
                $scope.Attachments3 = new Array();
                $scope.Attachments4 = new Array();
                $scope.Attachments5 = new Array();
                $scope.unupload1 = new Array();
                $scope.unupload2 = new Array();
                $scope.unupload3 = new Array();
                $scope.unupload4 = new Array();
                $scope.unupload5 = new Array();
                if (data.value.Attachments == null) {
                } else {
                    for (var i = 0; i < data.value.Attachments.length; i++) {
                        if (data.value.Attachments[i].ClassId == 1) {
                            $scope.Attachments1.push(data.value.Attachments[i]);
                        }
                        else if (data.value.Attachments[i].ClassId == 2) {
                            $scope.Attachments2.push(data.value.Attachments[i]);
                        }
                        else if (data.value.Attachments[i].ClassId == 3) {
                            $scope.Attachments3.push(data.value.Attachments[i]);
                        }
                        else if (data.value.Attachments[i].ClassId == 4) {
                            $scope.Attachments4.push(data.value.Attachments[i]);
                        }
                        else if (data.value.Attachments[i].ClassId == 5) {
                            $scope.Attachments5.push(data.value.Attachments[i]);
                        }
                    }
                }
                $scope.list1 = $scope.Attachments1.length;
                $scope.list2 = $scope.Attachments2.length;
                $scope.list3 = $scope.Attachments3.length;
                $scope.list4 = $scope.Attachments4.length;
                $scope.list5 = $scope.Attachments5.length;
                if (data.value.OptionsList == null) {
                } else {
                    for (var i = 1; i < 20; i++) {
                        if (typeof (data.value.OptionsList[i]) != "undefined") {
                            $("#input-" + i).addClass('checked');
                            $("#input-" + i).parent().find('label').addClass("hover");
                            $("#input-" + i).parent().parent().next().show()
                            $("#input-" + i).parent().parent().next().next().show()
                            $("#Rinput-" + i).val(data.value.OptionsList[i]);
                        }
                    }
                }
            });
        } else {
            var data = {
            };
            data.value = JSON.parse(lixian);
            $scope.olddata = data.value;
            $scope.OptionsList = data.value.OptionsList;
            $scope.NewOptionsList = {
            };
            $scope.NewOptionsList1 = {
            };
            $scope.NewOptionsList2 = {
            };
            $scope.Attachments1 = new Array();
            $scope.Attachments2 = new Array();
            $scope.Attachments3 = new Array();
            $scope.Attachments4 = new Array();
            $scope.Attachments5 = new Array();
            $scope.unupload1 = new Array();
            $scope.unupload2 = new Array();
            $scope.unupload3 = new Array();
            $scope.unupload4 = new Array();
            $scope.unupload5 = new Array();
            if (data.value.Attachments == null) {
            } else {
                for (var i = 0; i < data.value.Attachments.length; i++) {
                    if (data.value.Attachments[i].ClassId == 1) {
                        $scope.Attachments1.push(data.value.Attachments[i]);
                    }
                    else if (data.value.Attachments[i].ClassId == 2) {
                        $scope.Attachments2.push(data.value.Attachments[i]);
                    }
                    else if (data.value.Attachments[i].ClassId == 3) {
                        $scope.Attachments3.push(data.value.Attachments[i]);
                    }
                    else if (data.value.Attachments[i].ClassId == 4) {
                        $scope.Attachments4.push(data.value.Attachments[i]);
                    }
                    else if (data.value.Attachments[i].ClassId == 5) {
                        $scope.Attachments5.push(data.value.Attachments[i]);
                    }
                }
            }
            $scope.list1 = $scope.Attachments1.length;
            $scope.list2 = $scope.Attachments2.length;
            $scope.list3 = $scope.Attachments3.length;
            $scope.list4 = $scope.Attachments4.length;
            $scope.list5 = $scope.Attachments5.length;
            if (data.value.OptionsList == null) {
            } else {
                for (var i = 1; i < 20; i++) {
                    if (typeof (data.value.OptionsList[i]) != "undefined") {
                        $("#input-" + i).addClass('checked');
                        $("#input-" + i).parent().find('label').addClass("hover");
                        $("#input-" + i).parent().parent().next().show()
                        $("#input-" + i).parent().parent().next().next().show()
                        $("#Rinput-" + i).val(data.value.OptionsList[i]);
                    }
                }
            }
        }
    });
    $(".input-style1 input").click(function () {
        var id = $(this).attr("id").replace("Rinput-", "")
        window.localStorage.setItem("fjid", id);
    })
    $(".add-img").click(function () {
        var id = $(this).attr("id").replace("addimg", "");
        window.localStorage.setItem("fjimgid", id);
        var title = $(".page" + id).find(".container-title-main").html();
        $("#title").html(title)
        $(".speak").show();
    })
    $scope.takeimg = function () {
        WebcamApp.doWebcamApp("photo", "http://fileupload.openxt.com/ueditor/controller.ashx", {
            action: "uploadimage"
        }, false, function (code) {
            var data = JSON.parse(code);
            var fj = {
                "type": 1, "data": data[0]
            };
            var fjid = window.localStorage.getItem("fjimgid");
            if (fjid == null || fjid == undefined) {
                alert("请先选择区域");
                return;
            }
            PreviewPictureApp.doPreviewPicture(data[0], function (success) {
                var result = "data:image/jpg;base64," + success;
                if (fjid == "1") {
                    $scope.unupload1.push(fj);
                    $scope.Attachments1.push({
                        "ClassId": 1, "FileTitle": data[0], "FileUrl": result
                    });
                } else if (fjid == "2") {
                    $scope.unupload2.push(fj);
                    $scope.Attachments2.push({
                        "ClassId": 2, "FileTitle": data[0], "FileUrl": result
                    });
                } else if (fjid == "3") {
                    $scope.unupload3.push(fj);
                    $scope.Attachments3.push({
                        "ClassId": 3, "FileTitle": data[0], "FileUrl": result
                    });
                } else if (fjid == "4") {
                    $scope.unupload4.push(fj);
                    $scope.Attachments4.push({
                        "ClassId": 4, "FileTitle": data[0], "FileUrl": result
                    });
                } else if (fjid == "5") {
                    $scope.unupload5.push(fj);
                    $scope.Attachments5.push({
                        "ClassId": 5, "FileTitle": data[0], "FileUrl": result
                    });
                }
            })
        }, function (error) {
            alert("保存失败");
            return;
        });
    }

    $scope.upimg = function () {
        FileUploadApp.doFileUploadApp("http://fileupload.openxt.com/ueditor/controller.ashx", {
            action: "uploadimage"
        }, "*", false, function (str) {
            var data = JSON.parse(str);
            var fj = {
                "type": 1, "data": data[0]
            };
            var fjid = window.localStorage.getItem("fjimgid");
            if (fjid == null || fjid == undefined) {
                alert("请先选择区域");
                return;
            }
            PreviewPictureApp.doPreviewPicture(data[0], function (success) {
                var result = "data:image/jpg;base64," + success;
                if (fjid == "1") {
                    $scope.unupload1.push(fj);
                    $scope.Attachments1.push({
                        "ClassId": 1, "FileTitle": data[0], "FileUrl": result
                    });
                } else if (fjid == "2") {
                    $scope.unupload2.push(fj);
                    $scope.Attachments2.push({
                        "ClassId": 2, "FileTitle": data[0], "FileUrl": result
                    });
                } else if (fjid == "3") {
                    $scope.unupload3.push(fj);
                    $scope.Attachments3.push({
                        "ClassId": 3, "FileTitle": data[0], "FileUrl": result
                    });
                } else if (fjid == "4") {
                    $scope.unupload4.push(fj);
                    $scope.Attachments4.push({
                        "ClassId": 4, "FileTitle": data[0], "FileUrl": result
                    });
                } else if (fjid == "5") {
                    $scope.unupload5.push(fj);
                    $scope.Attachments5.push({
                        "ClassId": 5, "FileTitle": data[0], "FileUrl": result
                    });
                }
            })
        }, function (error) {
            alert("保存失败");
            return;
        });
    }
    $scope.sound = function () {
        RecordApp.doStartRecordApp("http://fileupload.openxt.com/ueditor/controller.ashx", -1, {
            action: "uploadfile"
        }, false, function (str) {
            var data = JSON.parse(str);
            var fj = {
                "type": 2, "data": data[0]
            };
            var fjid = window.localStorage.getItem("fjimgid");
            if (fjid == null || fjid == undefined) {
                alert("请先选择区域");
                return;
            }
            if (fjid == "1") {
                $scope.unupload1.push(fj);
                $scope.Attachments1.push({
                    "ClassId": 1, "FileTitle": data[0], "FileUrl": "Content/img/ht.png"
                });
            } else if (fjid == "2") {
                $scope.unupload2.push(fj);
                $scope.Attachments2.push({
                    "ClassId": 2, "FileTitle": data[0], "FileUrl": "Content/img/ht.png"
                });
            } else if (fjid == "3") {
                $scope.unupload3.push(fj);
                $scope.Attachments3.push({
                    "ClassId": 3, "FileTitle": data[0], "FileUrl": "Content/img/ht.png"
                });
            } else if (fjid == "4") {
                $scope.unupload4.push(fj);
                $scope.Attachments4.push({
                    "ClassId": 4, "FileTitle": data[0], "FileUrl": "Content/img/ht.png"
                });
            } else if (fjid == "5") {
                $scope.unupload5.push(fj);
                $scope.Attachments5.push({
                    "ClassId": 5, "FileTitle": data[0], "FileUrl": "Content/img/ht.png"
                });
            }
        }, function (error) {
            alert("保存失败");
            return;
        });
    }
    $scope.speakyy = function () {
        VoiceApp.doStartRecognizerApp(function (code) {
            var fjid = window.localStorage.getItem("fjid");
            $("#Rinput-" + fjid).val(code)
        })
    }
    //删除附件
    $scope.delimg = function (index) {
        $scope.Attachments1.remove(index);
        if (index >= $scope.list1) {
            $scope.unupload1.remove((index - $scope.list1 + 1));
        } else {
            $scope.list1 = $scope.list1 - 1;
        }
    }
    $scope.delimg2 = function (index) {
        $scope.Attachments2.remove(index);
        if (index >= $scope.list2) {
            $scope.unupload2.remove((index - $scope.list2 + 1));
        } else {
            $scope.list2 = $scope.list2 - 1;
        }
    }
    $scope.delimg3 = function (index) {
        $scope.Attachments3.remove(index);
        if (index >= $scope.list3) {
            $scope.unupload3.remove((index - $scope.list3 + 1));
        } else {
            $scope.list3 = $scope.list3 - 1;
        }
    }
    $scope.delimg4 = function (index) {
        $scope.Attachments4.remove(index);
        if (index >= $scope.list4) {
            $scope.unupload4.remove((index - $scope.list4 + 1));
        } else {
            $scope.list4 = $scope.list4 - 1;
        }
    }
    $scope.delimg5 = function (index) {
        $scope.Attachments5.remove(index);
        if (index >= $scope.list5) {
            $scope.unupload5.remove((index - $scope.list5 + 1));
        } else {
            $scope.list5 = $scope.list5 - 1;
        }
    }
    $scope.xchose = function (id) {
        if ($("#xinput" + id).hasClass("checked")) {
            $("#xinput" + id).removeClass("checked")
        } else {
            $("#xinput" + id).addClass('checked');
        }
    }
    $scope.next1 = function () {
        for (var i = 1; i < 9; i++) {
            if ($("#input-" + i).hasClass("checked")) {
                $scope.NewOptionsList[i] = document.getElementById("Rinput-" + i).value;
                $scope.NewOptionsList1[i] = document.getElementById("Rinput-" + i).value;
            }
        }
        $(".page1").hide();
        $(".page2").show();
    }
    $scope.next2 = function () {
        for (var i = 9; i < 20; i++) {
            if ($("#input-" + i).hasClass("checked")) {
                $scope.NewOptionsList[i] = document.getElementById("Rinput-" + i).value;
                $scope.NewOptionsList2[i] = document.getElementById("Rinput-" + i).value;
            }
        }
        if ($scope.olddata["QxieQk"] == undefined || $scope.olddata["QxieQk"] == null) {
        } else {
            document.getElementById("cinput").value = $scope.olddata["QxieQk"];
        }
        $(".page2").hide();
        $(".page3").show();
    }
    $scope.next3 = function () {
        if ($scope.olddata["OtherQk"] == null) {
        } else {
            document.getElementById("ginput").value = $scope.olddata["OtherQk"];
        }
        $(".page3").hide();
        $(".page4").show();
    }
    $scope.next4 = function () {
        var xiang = $scope.olddata.XiangQk;
        if (xiang == null) {
        } else {
            var xiang2 = new Array();
            xiang2 = xiang.split(",");
            for (var j = 0; j < xiang2.length; j++) {
                for (var i = 0; i < $scope.xiang.length; i++) {
                    if (parseFloat(xiang2[j]) == $scope.xiang[i].CODEID) {
                        $("#xinput" + i).addClass('checked');
                    }
                }
            }
        }
        $(".page4").hide();
        $(".page5").show();
    }
    $scope.next5 = function () {
        var Xiangarr = new Array();
        var Xiangarr2 = new Array();
        if ($scope.xiang == null) {
        } else {
            for (var i = 0; i < $scope.xiang.length; i++) {
                if ($("#xinput" + i).hasClass("checked")) {
                    var value = document.getElementById("xinput" + i).value;
                    var value2 = document.getElementById("xinput" + i).title;
                    Xiangarr.push(value);
                    Xiangarr2.push(value2);
                }
            }
        }
        if ($scope.olddata["PatrolHouse"] == null || $scope.olddata["PatrolHouse"] == undefined) {
        } else {
            document.getElementById("huhao").value = $scope.olddata["PatrolHouse"];
        }
        if ($scope.olddata["ChuLiQk"] == null || $scope.olddata["ChuLiQk"] == undefined) {
        } else {
            document.getElementById("chuli").value = $scope.olddata["ChuLiQk"];
        }
        if (Xiangarr == null) {
        } else {
            $scope.XiangQk = Xiangarr.join(",");
        }
        if (Xiangarr2 == null) {
        } else {
            $scope.XiangQk2 = Xiangarr2.join("  ");
        }
        var Attachments = new Array();
        if (typeof ($scope.Attachments1) === "object" && $scope.Attachments1.length > 0) {
            Attachments = Attachments.concat($scope.Attachments1);
            $scope.Attachments1 = null;
        }
        if (typeof ($scope.Attachments2) === "object" && $scope.Attachments2.length > 0) {
            Attachments = Attachments.concat($scope.Attachments2);
            $scope.Attachments2 = null;
        }
        if (typeof ($scope.Attachments3) === "object" && $scope.Attachments3.length > 0) {
            Attachments = Attachments.concat($scope.Attachments3);
            $scope.Attachments3 = null;
        }
        if (typeof ($scope.Attachments4) === "object" && $scope.Attachments4.length > 0) {
            Attachments = Attachments.concat($scope.Attachments4);
            $scope.Attachments4 = null;
        }
        if (typeof ($scope.Attachments5) === "object" && $scope.Attachments5.length > 0) {
            Attachments = Attachments.concat($scope.Attachments5);
            $scope.Attachments5 = null;
        }
        $scope.allAttachments = Attachments;
        $(".page5").hide();
        $(".page6").show();
    }
    $scope.next6 = function () {
        if (document.getElementById("huhao").value == undefined || document.getElementById("huhao").value == null || document.getElementById("huhao").value == "") {
            alert("请输入户号")
            return;
        }
        $scope.PatrolHouse2 = document.getElementById("huhao").value;
        $(".page6").hide();
        $(".page7").show();
    }
    $scope.next7 = function () {
        var xuncha = document.getElementById("xtime").value;
        if (xuncha == "" || xuncha == null) {
            alert("巡查日期不能为空");
            return;
        }
        $scope.PatrolDate2 = xuncha;
        $scope.SGradeID = $scope.olddata.SGradeID;
        $scope.ZongHeID = $scope.olddata.ZongHeID;
        $(".page7").hide();
        $(".page8").show();
    }
    $scope.next8 = function () {
        if ($scope.SGradeID == 0) {
            alert("请选择损坏等级");
            return
        }
        if ($scope.ZongHeID == 0) {
            alert("请选择综合等级");
            return
        }
        for (var i = 0; i < $scope.sunhuai.length; i++) {
            if ($scope.sunhuai[i].CODEID == $scope.SGradeID) $scope.SGradeID2 = $scope.sunhuai[i].CODENAME;
        }
        for (var i = 0; i < $scope.zonghe.length; i++) {
            if ($scope.zonghe[i].CODEID == $scope.ZongHeID) $scope.ZongHeID2 = $scope.zonghe[i].CODENO;
        }
        for (var i = 1; i < 20; i++) {
            if (typeof ($scope.NewOptionsList[i]) != "undefined") {
                $("#flist" + i).show();
                $("#bflist" + i).html($scope.NewOptionsList[i]);
            }
        }
        $(".page8").hide();
        $(".page9").show();
    }
    $scope.lxsub = function () {
        var lixian = {
        };
        lixian.Attachments = $scope.allAttachments;
        lixian.ChuLiQk = $scope.ChuLiQk;
        lixian.HouseID = $scope.HouseID;
        lixian.OptionsList = $scope.NewOptionsList;
        lixian.OtherQk = $scope.OtherQk2;
        lixian.PatrolDate = $scope.PatrolDate2;
        lixian.PatrolHouse = $scope.PatrolHouse2;
        lixian.QxieQk = $scope.QxieQk2;
        lixian.SGradeID = $scope.SGradeID;
        lixian.TaskID = $scope.info.MissionCode;
        lixian.XiangQk = $scope.XiangQk;
        lixian.ZongHeID = $scope.ZongHeID;
        var lixian2 = JSON.stringify(lixian);
        window.localStorage.setItem($scope.info["MissionCode"], lixian2);
        var unupload = new Array();
        unupload = $scope.unupload1.concat($scope.unupload2, $scope.unupload3, $scope.unupload4, $scope.unupload5);
        $scope.unupload1 = null;
        $scope.unupload2 = null;
        $scope.unupload3 = null;
        $scope.unupload4 = null;
        $scope.unupload5 = null;
        var unupload2 = JSON.stringify(unupload);
        window.localStorage.setItem($scope.info["MissionCode"] + "unupload", unupload2);
        alert("离线保存成功")
        $location.path("/patroltask")
    }
    $scope.zxsub = function () {
        var unupload3 = new Array();
        var unupload = new Array();
        if (typeof ($scope.unupload1) === "object" && $scope.unupload1.length > 0) {
            unupload3 = unupload3.concat($scope.unupload1);
            $scope.unupload1 = null;
        }
        if (typeof ($scope.unupload2) === "object" && $scope.unupload2.length > 0) {
            unupload3 = unupload3.concat($scope.unupload2);
            $scope.unupload2 = null;
        }
        if (typeof ($scope.unupload3) === "object" && $scope.unupload3.length > 0) {
            unupload3 = unupload3.concat($scope.unupload3);
            $scope.unupload3 = null;
        }
        if (typeof ($scope.unupload4) === "object" && $scope.unupload4.length > 0) {
            unupload3 = unupload3.concat($scope.unupload4);
            $scope.unupload4 = null;
        }
        if (typeof ($scope.unupload5) === "object" && $scope.unupload5.length > 0) {
            unupload3 = unupload3.concat($scope.unupload5);
            $scope.unupload5 = null;
        }
        var uploaded = window.localStorage.getItem($scope.info["MissionCode"] + "uploaded");
        var unupload2 = window.localStorage.getItem($scope.info["MissionCode"] + "unupload");
        if (uploaded != null && uploaded != undefined) {
            var unupload = JSON.parse(unupload2);
        } else if (unupload2 != null && unupload2 != undefined) {
            var unupload = JSON.parse(unupload2);
        } else {
            var unupload = unupload3;
        }
        var unuploadlen = unupload.length;
        if (unupload.length > 0) {
            for (var i = 0; i < unuploadlen; i++) {
                FileUploadApp.doInstantFileUploadApp("http://fileupload.openxt.com/ueditor/controller.ashx", {
                    action: "uploadfile"
                }, unupload[i].data, function (str) {
                    var result = JSON.parse(str);
                    alert(unupload.data + "上传成功");
                    uploaded.push(unupload[i]);
                    window.localStorage.setItem($scope.info["MissionCode"] + "uploaded", uploaded);
                    unupload.remove(i);
                    window.localStorage.setItem($scope.info["MissionCode"] + "unupload", unupload);
                    for (var j = 0; j < $scope.allAttachments.length; j++) {
                        if ($scope.allAttachments[j].FileTitle == unupload[i].data) {
                            $scope.allAttachments[j].FileUrl = result["prefix"] + result["url"];
                        }
                    }
                    if (unupload.length == 0) {
                        var user = window.localStorage.getItem("User");
                        var zaixian = {
                        };
                        zaixian.Attachments = $scope.allAttachments;
                        zaixian.ChuLiQk = $scope.ChuLiQk;
                        zaixian.HouseID = $scope.info.HouseID;
                        zaixian.OptionsList = $scope.NewOptionsList;
                        zaixian.OtherQk = $scope.OtherQk2;
                        zaixian.PatrolDate = $scope.PatrolDate2;
                        zaixian.PatrolHouse = $scope.PatrolHouse2;
                        zaixian.QxieQk = $scope.QxieQk2;
                        zaixian.SGradeID = $scope.SGradeID;
                        zaixian.TaskID = $scope.info.MissionCode;
                        zaixian.XiangQk = $scope.XiangQk;
                        zaixian.ZongHeID = $scope.ZongHeID;
                        var zaixian2 = JSON.stringify(zaixian);
                        $http.post(sytdapp.APIHOST + "HousePatrol/AddPatrol?cid=" + user, { models: zaixian2 }).success(function (data) {
                            if (data.level == 0) {
                                alert("在线提交成功!")
                                window.localStorage.removeItem($scope.info["MissionCode"]);
                                window.localStorage.removeItem($scope.info["MissionCode"] + "uploaded");
                                window.localStorage.removeItem($scope.info["MissionCode"] + "unupload");
                                $location.path("/patroltask")
                            } else {
                                alert("在线提交失败!")
                            }
                        }).error(function (data, status, headers, config) {
                            alert("网络不通/服务停止");
                            $location.path("/");
                        });
                    }
                }, function (error) {
                    alert("上传失败!请再次提交，重新上传" + error);
                    return;
                });
            }
        } else {
            var user = window.localStorage.getItem("User");
            var zaixian = {
            };
            zaixian.Attachments = $scope.allAttachments;
            zaixian.ChuLiQk = $scope.ChuLiQk;
            zaixian.HouseID = $scope.info.HouseID;
            zaixian.OptionsList = $scope.NewOptionsList;
            zaixian.OtherQk = $scope.OtherQk2;
            zaixian.PatrolDate = $scope.PatrolDate2;
            zaixian.PatrolHouse = $scope.PatrolHouse2;
            zaixian.QxieQk = $scope.QxieQk2;
            zaixian.SGradeID = $scope.SGradeID;
            zaixian.TaskID = $scope.info.MissionCode;
            zaixian.XiangQk = $scope.XiangQk;
            zaixian.ZongHeID = $scope.ZongHeID;
            var zaixian2 = JSON.stringify(zaixian);
            fac.get("登记巡查任务", "HousePatrol/AddPatrol", function (data) {
                if (data.level == 0) {
                    alert("在线提交成功!")
                    window.localStorage.removeItem($scope.info["MissionCode"]);
                    window.localStorage.removeItem($scope.info["MissionCode"] + "uploaded");
                    window.localStorage.removeItem($scope.info["MissionCode"] + "unupload");
                    $location.path("/patroltask")
                } else {
                    alert("在线提交失败!")
                }
            }, {
                data: {
                    models: zaixian2
                }
            });
        }
    }
}]);
//装修巡查任务列表
app.controller("PadelogController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {

    //fac.accessStatistics("#/padelog");
    //$scope.back = function () {
    //    $location.path("/patrol");
    //}
    $scope.page = 1;
    $scope.rows = 10;
    var customerid = window.localStorage.getItem("User");
    var patroltaskid = window.localStorage.getItem("Patroltaskid");
    if (patroltaskid == null || patroltaskid == undefined) patroltaskid = "";
    //待处理
    fac.get("巡查任务待处理", "HousePatrol/GetDHMission?missioncode=&missiontype=" + 0 + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows + "&houseid=", function (data) {
        $scope.list = data.value;
    });
    $scope.getdata = function () {
        $scope.page++;
        var patroltaskid = window.localStorage.getItem("Patroltaskid");
        if (patroltaskid == null) patroltaskid = "";
        fac.get("巡查任务待处理", "HousePatrol/GetDHMission?missioncode=&missiontype=" + 0 + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows + "&houseid=" + patroltaskid, function (data) {
            $scope.list = $scope.list.concat(data.value);
        });
    }
    $scope.log = function (id) {
        $location.path("/padelogd/" + id);
    }
}]);
//装修巡查登记
app.controller("PadelogDControllerController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {

    //fac.accessStatistics("#/padelogd");
    $scope.back = function () {
        var lixian = window.localStorage.getItem($scope.info["pdMissionCode"]);
        var unupload = window.localStorage.getItem($scope.info["pdMissionCode"] + "unupload");
        if ((lixian == undefined || lixian == null) && (unupload == undefined || unupload == null)) {
            //$location.path("/patroltask")
            fac.trackRecord.back($location);
        } else {
            if (confirm("尚未离线保存,确认退出？")) {
                //$location.path("/patroltask")
                fac.trackRecord.back($location);
            }
            //$location.path("/patroltask")
            //fac.trackRecord.back($location);
        }
    }
    //获得房屋基本信息
    fac.get("装修任务单个", "HousePatrol/Get?id=" + $routeParams.id, function (data) {
        $scope.info = data;
        var user = window.localStorage.getItem("User");
        var lixian = window.localStorage.getItem($scope.info["pdMissionCode"]);
        if (lixian == undefined || lixian == null) {
            fac.get("装修任务单个详细", "HousePatrol/GetSingle?taskid=" + $routeParams.id, function (data) {
                $scope.olddata = data.value;
                $scope.OptionsList = data.value.OptionsList;
                $scope.Attachments = new Array();
                $scope.unupload = new Array();
                $scope.list = $scope.Attachments.length;
                if (data.value.OptionsList == null) {
                } else {
                    for (var i = 1; i < 7; i++) {
                        if (typeof (data.value.OptionsList[i]) != "undefined") {
                            $("#input-" + i).addClass('checked');
                            $("#input-" + i).parent().find('label').addClass("hover");
                            $("#input-" + i).parent().parent().next().show()
                            $("#input-" + i).parent().parent().next().next().show()
                            $("#Rinput-" + i).val(data.value.OptionsList[i]);
                        }
                    }
                }
            })
        } else {
            var data = {
            };
            data.value = JSON.parse(lixian);
            $scope.olddata = data.value;
            $scope.OptionsList = data.value.OptionsList;
            $scope.NewOptionsList = {
            };
            $scope.Attachments = new Array();
            $scope.unupload = new Array();
            $scope.list = $scope.Attachments.length;
            if (data.value.OptionsList == null) {
            } else {
                for (var i = 1; i < 7; i++) {
                    if (typeof (data.value.OptionsList[i]) != "undefined") {
                        $("#input-" + i).addClass('checked');
                        $("#input-" + i).parent().find('label').addClass("hover");
                        $("#input-" + i).parent().parent().next().show()
                        $("#input-" + i).parent().parent().next().next().show()
                        $("#Rinput-" + i).val(data.value.OptionsList[i]);
                    }
                }
            }
        }
    });
    $(".input-style1 input").click(function () {
        var id = $(this).attr("id").replace("Rinput-", "")
        window.localStorage.setItem("fjid", id);
    })
    $scope.takeimg = function () {
        WebcamApp.doWebcamApp("photo", "http://fileupload.openxt.com/ueditor/controller.ashx", {
            action: "uploadimage"
        }, false, function (code) {
            var data = JSON.parse(code);
            var fj = {
                "type": 1, "data": data[0]
            };
            //var fjid = window.localStorage.getItem("fjimgid");
            //if (fjid == null || fjid == undefined) {
            //    alert("请先选择区域");
            //    return;
            //}
            PreviewPictureApp.doPreviewPicture(data[0], function (success) {
                var result = "data:image/jpg;base64," + success;
                $scope.unupload.push(fj);
                $scope.Attachments.push({
                    "ClassId": 1, "FileTitle": data[0], "FileUrl": result
                });
            })
        }, function (error) {
            alert("保存失败");
            return;
        });
    }

    $scope.upimg = function () {
        FileUploadApp.doFileUploadApp("http://fileupload.openxt.com/ueditor/controller.ashx", {
            action: "uploadimage"
        }, "*", false, function (str) {
            var data = JSON.parse(str);
            var fj = {
                "type": 1, "data": data[0]
            };
            //var fjid = window.localStorage.getItem("fjimgid");
            //if (fjid == null || fjid == undefined) {
            //    alert("请先选择区域");
            //    return;
            //}
            PreviewPictureApp.doPreviewPicture(data[0], function (success) {
                var result = "data:image/jpg;base64," + success;
                $scope.unupload.push(fj);
                $scope.Attachments.push({
                    "ClassId": 1, "FileTitle": data[0], "FileUrl": result
                });
            })
        }, function (error) {
            alert("保存失败");
            return;
        });
    }
    $scope.sound = function () {
        RecordApp.doStartRecordApp("http://fileupload.openxt.com/ueditor/controller.ashx", -1, {
            action: "uploadfile"
        }, false, function (str) {
            var data = JSON.parse(str);
            var fj = {
                "type": 2, "data": data[0]
            };
            //var fjid = window.localStorage.getItem("fjimgid");
            //if (fjid == null || fjid == undefined) {
            //    alert("请先选择区域");
            //    return;
            //}
            $scope.unupload.push(fj);
            $scope.Attachments.push({
                "ClassId": 1, "FileTitle": data[0], "FileUrl": "Content/img/ht.png"
            });
        }, function (error) {
            alert("保存失败");
            return;
        });
    }
    $scope.speakyy = function () {
        VoiceApp.doStartRecognizerApp(function (code) {
            var fjid = window.localStorage.getItem("fjid");
            $("#Rinput-" + fjid).val(code)
        })
    }
    //删除附件
    $scope.delimg = function (index) {
        $scope.Attachments.remove(index);
        if (index >= $scope.list) {
            $scope.unupload.remove((index - $scope.list + 1));
        } else {
            $scope.list = $scope.list - 1;
        }
    }
    $scope.xchose = function (id) {
        if ($("#xinput" + id).hasClass("checked")) {
            $("#xinput" + id).removeClass("checked")
        } else {
            $("#xinput" + id).addClass('checked');
        }
    }
    $scope.lxsub = function () {
        var lixian = {
        };
        lixian.Attachments = $scope.allAttachments;
        var lixian2 = JSON.stringify(lixian);
        window.localStorage.setItem($scope.info["pdMissionCode"], lixian2);
        var unupload = new Array();
        unupload = $scope.unupload;
        var unupload2 = JSON.stringify(unupload);
        window.localStorage.setItem($scope.info["pdMissionCode"] + "unupload", unupload2);
        alert("离线保存成功")
        $location.path("/patroltask")
    }
    $scope.zxsub = function () {
        var unupload3 = new Array();
        var unupload = new Array();
        if (typeof ($scope.unupload) === "object" && $scope.unupload.length > 0) {
            unupload3 = unupload3.concat($scope.unupload);
            $scope.unupload = null;
        }
        var uploaded = window.localStorage.getItem($scope.info["pdMissionCode"] + "uploaded");
        var unupload2 = window.localStorage.getItem($scope.info["pdMissionCode"] + "unupload");
        if (uploaded != null && uploaded != undefined) {
            var unupload = JSON.parse(unupload2);
        } else if (unupload2 != null && unupload2 != undefined) {
            var unupload = JSON.parse(unupload2);
        } else {
            var unupload = unupload3;
        }
        var unuploadlen = unupload.length;
        if (unupload.length > 0) {
            for (var i = 0; i < unuploadlen; i++) {
                FileUploadApp.doInstantFileUploadApp("http://fileupload.openxt.com/ueditor/controller.ashx", {
                    action: "uploadfile"
                }, unupload[i].data, function (str) {
                    var result = JSON.parse(str);
                    alert(unupload.data + "上传成功");
                    uploaded.push(unupload[i]);
                    window.localStorage.setItem($scope.info["pdMissionCode"] + "uploaded", uploaded);
                    unupload.remove(i);
                    window.localStorage.setItem($scope.info["pdMissionCode"] + "unupload", unupload);
                    for (var j = 0; j < $scope.allAttachments.length; j++) {
                        if ($scope.allAttachments[j].FileTitle == unupload[i].data) {
                            $scope.allAttachments[j].FileUrl = result["prefix"] + result["url"];
                        }
                    }
                    if (unupload.length == 0) {
                        var user = window.localStorage.getItem("User");
                        var zaixian = {
                        };
                        zaixian.Attachments = $scope.allAttachments;
                        zaixian.OptionsList = $scope.NewOptionsList;
                        var zaixian2 = JSON.stringify(zaixian);
                        $http.post(sytdapp.APIHOST + "HousePatrol/AddPatrol?cid=" + user, { models: zaixian2 }).success(function (data) {
                            if (data.level == 0) {
                                alert("在线提交成功!")
                                window.localStorage.removeItem($scope.info["pdMissionCode"]);
                                window.localStorage.removeItem($scope.info["pdMissionCode"] + "uploaded");
                                window.localStorage.removeItem($scope.info["pdMissionCode"] + "unupload");
                                $location.path("/patroltask")
                            } else {
                                alert("在线提交失败!")
                            }
                        }).error(function (data, status, headers, config) {
                            alert("网络不通/服务停止");
                            $location.path("/");
                        });
                    }
                }, function (error) {
                    alert("上传失败!请再次提交，重新上传" + error);
                    return;
                });
            }
        } else {
            var user = window.localStorage.getItem("User");
            var zaixian = {
            };
            zaixian.Attachments = $scope.allAttachments;
            zaixian.OptionsList = $scope.NewOptionsList;
            var zaixian2 = JSON.stringify(zaixian);
            fac.get("登记装修任务", "HousePatrol/AddPatrol", function (data) {
                if (data.level == 0) {
                    alert("在线提交成功!")
                    window.localStorage.removeItem($scope.info["pdMissionCode"]);
                    window.localStorage.removeItem($scope.info["pdMissionCode"] + "uploaded");
                    window.localStorage.removeItem($scope.info["pdMissionCode"] + "unupload");
                    $location.path("/patroltask")
                } else {
                    alert("在线提交失败!")
                }
            }, {
                data: {
                    models: zaixian2
                }
            })
        }
    }
}]);
//房屋定位
app.controller("ReHouseController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {

    //fac.accessStatistics("#/rehouse");
    //$scope.back = function () {
    //    $location.path("/patrol");
    //}
}]);
//个人中心
app.controller("CenterController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {

    //fac.accessStatistics("#/center");
    fac.get("客户信息", "Customer/Get", function (data) {
        $scope.name = data.NICKNAME;
        $scope.phone = data.TEL;
        if (data.IMAGE == "-") {
            $("#touxiang").attr("src", "Content/images/gr.jpg")
        } else {
            $("#touxiang").attr("src", data.IMAGE);
        }
    });
    fac.get("客户数据模型", "DataModel/Get", function (data) {
        var order = 0;
        for (var i = 0; i < data.length; i++) {
            if (data[i].ORDERSTATUS == "true") {
                order = order + 1;
                if (data[i].TYPE == 1) {
                    $scope.listName1 = data[i].Name;
                    $scope.page = 1;
                    $scope.rows = 2;
                    fac.get("客户巡查任务", "HousePatrol/GetMission?missioncode=&missiontype=" + 0 + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows + "&houseid=", function (data) {
                        $scope.list = data.value;
                    })
                } else if (data[i].TYPE == 2) {
                    $scope.listName2 = data[i].Name;
                    fac.get("公积金", "GJJ/GetCustomerGJJ", function (data) {
                        $scope.money = data.bal;
                    })
                    //var cardnumber = window.localStorage.getItem("cardnumber");
                    //var zhnumber = window.localStorage.getItem("zhnumber");
                    //if (cardnumber == null || cardnumber == undefined) {
                    //    fac.get("公积金详细", "GJJ/Query2?accnum=" + zhnumber, function (data) {
                    //        $scope.money = data.bal;
                    //    })
                    //} else if (zhnumber == null || zhnumber == undefined) {
                    //    fac.get("公积金详细", "GJJ/Query?certinum=" + cardnumber, function (data) {
                    //        $scope.money = data.bal;
                    //    })
                    //}
                }
            }
        }
        if (order == 0) {
            $(".gr-a").hide();
        } else if (order == 1 && data[0].ORDERSTATUS == "true") {
            $("#work1").remove();
        } else if (order == 1 && data[1].ORDERSTATUS == "true") {
            $("#work2").remove();
        }
    })
    fac.get("客户订阅信息", "Subscribe/GetCustomerSubscribe", function (data) {
        var allitem = 0
        for (var i = 0; i < data.length; i++) {
            for (var j = 0; j < data[i].length; j++) {
                allitem += 1;
            }
        }
        var count = Math.ceil(allitem / 4) - 1;
        if (allitem % 4 == 1) {
            $("#td" + count + "l1").show();
            $("#td" + count + "l2").show();
            $("#td" + count + "l3").show();
        } else if (allitem % 4 == 2) {
            $("#td" + count + "l1").show();
            $("#td" + count + "l2").show();
            $("#td" + count + "l3").hide();
        } else if (allitem % 4 == 3) {
            $("#td" + count + "l1").show();
            $("#td" + count + "l2").hide();
            $("#td" + count + "l3").hide();
        } else {
            $("#td" + count + "l1").hide();
            $("#td" + count + "l2").hide();
            $("#td" + count + "l3").hide();
        }
        $scope.dylist = data;
    })
    $scope.back = function () {
        fac.trackRecord.back($location);
    }
    $scope.logout = function () {
        if (confirm("确认退出？")) {
            window.localStorage.removeItem("User");
            alert("退出成功");
            //$location.path("/");
            fac.redirect2Index();
        }
    }
    $scope.detail = function (id) {
        $location.path("/patroltaskd/" + id);
    }
    $scope.upttx = function () {
        FileUploadApp.doFileUploadApp("http://fileupload.openxt.com/ueditor/controller.ashx", {
            action: "uploadimage"
        }, "*", false, function (str) {
            var img = JSON.parse(str);
            if (img != null) {
                FileUploadApp.doInstantFileUploadApp("http://fileupload.openxt.com/ueditor/controller.ashx", {
                    action: "uploadfile"
                }, img, function (str) {
                    var result = JSON.parse(str);
                    var url = result["prefix"] + result["url"]
                    fac.get("客户修改头像", "Customer/UptImage?url=" + url, function (data) {
                        $("#touxiang").attr("src", url);
                    })
                }, function (error) {
                    alert("上传失败!" + error);
                    return;
                });
            }
        }, function (error) {
            alert("上传失败!" + error);
            return;
        });
    }
}]);
//修改密码
app.controller("UptPwdController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("修改密码", function () {
        //fac.accessStatistics("#/uptpwd");
        //$scope.back = function () {
        //    $location.path("/center");
        //}
        $scope.uptpwd = function () {
            if ($scope.oldpwd == null || $scope.oldpwd == "") {
                alert({
                    'tip': '原密码不能为空',
                });
                //alert("原密码不能为空");
                return;
            }
            if ($scope.oldpwd.length < 6 || $scope.oldpwd.length > 16) {
                alert({
                    'tip': '原密码长度应在6~16位之间',
                });
                //alert("原密码长度应在6~16位之间");
                return;
            }
            if ($scope.newpwd == null || $scope.newpwd == "") {
                alert({
                    'tip': '新密码不能为空',
                });
                //alert("新密码不能为空");
                return;
            }
            if ($scope.newpwd.length < 6 || $scope.newpwd.length > 16) {
                alert({
                    'tip': '新密码长度应在6~16位之间',
                });
                //alert("新密码长度应在6~16位之间");
                return;
            }
            if ($scope.newpwd != $scope.newpwd2) {
                alert({
                    'tip': '两次密码输入不一致',
                });
                //alert("两次密码输入不一致");
                return;
            }
            fac.get("修改密码", "customer/UpdatePassWord?oldpwd=" + $scope.oldpwd + "&newpwd=" + $scope.newpwd, function (data) {
                if (data == true) {
                    //alert("密码修改成功");
                    sytdapp.LoggedUser.clear();
                    alert({
                        'tip': '密码修改成功',
                        confirmCallback: function () {
                            AppConfigModel.doGoPageApp("#/login");
                        }
                    });
                    //$location.path("/login");
                    //fac.redirect2login();
                } else {
                    alert({
                        'tip': '密码修改失败',
                    });
                    //alert("密码修改失败");
                }
            });
        }
    });
}]);
//修改昵称
app.controller("UptNameController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {

    //fac.accessStatistics("#/uptname");
    //$scope.back = function () {
    //    $location.path("/center");
    //}
    $scope.uptname = function () {
        if ($scope.name == "" || $scope.name == null) {
            alert("昵称不能为空");
            return;
        }
        var totalCount = 0;
        for (var i = 0; i < $scope.name.length; i++) {
            var c = $scope.name.charCodeAt(i);
            if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
                totalCount++;
            } else {
                totalCount += 2;
            }
        }
        if (totalCount > 12) {
            alert("昵称应为6个汉字或12个字母")
            return;
        }
        fac.get("修改昵称", "customer/UpdateNickName?nikename=" + $scope.name, function (data) {
            if (data == true) {
                alert("昵称修改成功");
                //$location.path("/center");
                fac.redirect2Center();
            } else {
                alert("昵称修改失败");
            }
        });
    }
}]);
//修改手机
app.controller("UptPhoneController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("修改手机", function () {
        //fac.accessStatistics("#/uptphone");
        //$scope.back = function () {
        //    $location.path("/center");
        //}
        $scope.sendstatus = 0;
        $scope.yzmstatus = 1;
        $scope.getyzm = function () {
            if ($scope.newphone == null || $scope.newphone == "") {
                alert({
                    'tip': '新手机号不能为空',
                });
                //alert("新手机号不能为空")
                return;
            }
            if (!/^1[3|4|5|7|8]\d{9}$/.test($scope.newphone)) {
                alert({
                    'tip': '新手机号格式错误',
                });
                //alert("新手机号格式错误");
            } else {
                if ($scope.yzmstatus) {
                    $scope.yzmstatus = 0;
                    var vcode_time = 30;
                    var vcode_id = $("#tel");
                    if ($(vcode_id).hasClass('on')) { } else {
                        $(vcode_id).addClass("on");
                        var msg_num = setInterval(function () {
                            $(vcode_id).find("a").html(vcode_time + "秒后重发");
                            vcode_time = vcode_time - 1
                            if (vcode_time == 0) {
                                clearInterval(msg_num);
                                $(vcode_id).find("a").html("重新获取");
                                $scope.yzmstatus = 1;
                                vcode_time = vcode_time;
                                $(vcode_id).removeClass("on");
                            }
                        }, 1000)
                    }
                    fac.get("获得验证码", "verification/Send?tel=" + $scope.newphone, function (data) {
                        if (data.type) {
                            alert({
                                'tip': data.msg,
                            });
                            //alert(data.msg);
                            //$scope.yzmstatus = 0;
                            //var vcode_time = 30;
                            //var vcode_id = $("#tel");
                            //if ($(vcode_id).hasClass('on')) { } else {
                            //    $(vcode_id).addClass("on");
                            //    var msg_num = setInterval(function () {
                            //        $(vcode_id).find("a").html(vcode_time + "秒后重发");
                            //        vcode_time = vcode_time - 1
                            //        if (vcode_time == 0) {
                            //            clearInterval(msg_num);
                            //            $(vcode_id).find("a").html("重新获取");
                            //            $scope.yzmstatus = 1;
                            //            vcode_time = vcode_time;
                            //            $(vcode_id).removeClass("on");
                            //        }
                            //    }, 1000)
                            //}
                            $scope.sendstatus = 1;
                        } else {
                            alert({
                                'tip': data.msg,
                            });
                            //alert(data.msg);
                        }
                    });
                }
            }
        }
        $scope.uptphone = function () {
            if ($scope.sendstatus) {
                if ($scope.oldphone == null || $scope.oldphone == "") {
                    alert({
                        'tip': '原手机号不能为空',
                    });
                    //alert("原手机号不能为空");
                    return;
                }
                if (!/^1[3|4|5|7|8]\d{9}$/.test($scope.oldphone)) {
                    alert({
                        'tip': '原手机号格式错误',
                    });
                    //alert("原手机号格式错误");
                    return;
                }
                if (!/^\d{6}$/.test($scope.yzm)) {
                    alert({
                        'tip': '手机验证码格式错误',
                    });
                    //alert("手机验证码格式错误");
                    return;
                }
                fac.get("修改手机", "customer/UpdateMobile?oldmobile=" + $scope.oldphone + "&newmobile=" + $scope.newphone + "&verification=" + $scope.yzm, function (data) {
                    if (data == true) {
                        alert({
                            'tip': '绑定手机更换成功',
                            confirmCallback: function () {
                                AppConfigModel.doGoPageApp("#/login");
                            }
                        });
                        //alert("绑定手机更换成功");
                        //$location.path("/login");
                        //fac.redirect2login();
                    } else {
                        alert({
                            'tip': '绑定手机更换失败',
                        });
                        //alert("绑定手机更换失败");
                    }
                });
            } else {
                alert({
                    'tip': '请先发送验证码',
                });
                //alert("请先发送验证码");
            }
        }
    });
}]);
//我的订阅
app.controller("MOrderController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {

    //fac.accessStatistics("#/morder");
    //$scope.back = function () {
    //    $location.path("/")
    //}
    fac.get("我的订阅", "Subscribe/GetCustomerSUBSCRIBEAll", function (data) {
        $scope.datas = new Array();
        for (var i = 0; i < data.length; i++) {
            for (var j = 0; j < data[i].length; j++) {
                $scope.datas.push(data[i][j]);
            }
        }
        $scope.list = data;
    })
    $scope.chose = function (id) {
        if ($("#" + id).hasClass("on")) {
            for (var i = 0; i < $scope.datas.length; i++) {
                if ($scope.datas[i].ID == id) {
                    $scope.datas[i].STATUS = "false";
                    $("#" + id).removeClass("on")
                }
            }
        } else {
            for (var i = 0; i < $scope.datas.length; i++) {
                if ($scope.datas[i].ID == id) {
                    $scope.datas[i].STATUS = "true";
                    $("#" + id).addClass('on');
                }
            }
        }
    }
    $scope.order = function () {
        var datas = JSON.stringify($scope.datas);
        fac.post("订阅", "Subscribe/AddCustomerSubscribe", function (data) {
            if (data.level == 0) {
                alert("订阅成功");
                //$location.path("/");
                fac.redirect2Index();
            }
        }, {
            data: {
                "models": datas
            }
        })
    }
}]);
//数据模块
app.controller("UptMKController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {

    //fac.accessStatistics("#/uptmk");
    //$scope.back = function () {
    //    history.back();
    //}
    var user = window.localStorage.getItem("User");
    fac.get("数据模块", "DataModel/Get", function (data) {
        var dd = JSON.stringify(data)
        $scope.datas = JSON.parse(dd);
        $scope.dylist = data;
    })
    $scope.chose = function (id) {
        if ($("#" + id).hasClass("checked")) {
            for (var i = 0; i < $scope.datas.length; i++) {
                if ($scope.datas[i].ID == id) {
                    $scope.datas[i].ORDERSTATUS = "false";
                    $("#" + id).removeClass("checked")
                    $("#" + id).parent().find('label').removeClass("hover");
                }
            }
        } else {
            for (var i = 0; i < $scope.datas.length; i++) {
                if ($scope.datas[i].ID == id) {
                    $scope.datas[i].ORDERSTATUS = "true";
                    $("#" + id).addClass('checked');
                    $("#" + id).parent().find('label').addClass("hover");
                }
            }
        }
    }
    $scope.order = function () {
        for (var i = 0; i < $scope.datas.length; i++) {
            if ($scope.datas[i].TYPE == 2 && $scope.datas[i].ORDERSTATUS == "true") {
                var acct1 = window.localStorage.getItem("accnum");
                var acct2 = window.localStorage.getItem("certinum");
                //fac.get("公积金", "GJJ/GetCustomerGJJ", function (data) {
                if (acct1 == null && acct2 == null) {
                    alert("请先绑定公积金帐号");
                    $location.path("/gjjcx")
                    return;
                }
                //})
                //var cardnumber = window.localStorage.getItem("cardnumber");
                //var zhnumber = window.localStorage.getItem("zhnumber");
                //if ((cardnumber == null || cardnumber == undefined) && (zhnumber == null || zhnumber == undefined)) {
                //    alert("请先绑定公积金帐号");
                //    $location.path("/gjjcx")
                //}
            }
        }
        var datas = JSON.stringify($scope.datas);
        fac.post("订阅数据模块", "DataModel/AddCustomerModel", function (data) {
            if (data.level == 0) {
                alert("模块订阅成功");
                $location.path("/myitem");
                //fac.redirect2Center();
            }
        }, {
            data: {
                "models": datas
            }
        })
    }
}]);
//我的消息
app.controller("MessageController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {

    //fac.accessStatistics("#/message");
    //$scope.back = function () {
    //    $location.path("/center");
    //}
}]);
//登录
app.controller("LoginController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    //fac.accessStatistics("#/login");
    $scope.login = function () {
        if (!/^1[3|4|5|7|8]\d{9}$/.test($scope.phone)) {
            alert("手机号格式错误");
            return;
        }
        if (!(/\S{6,}/.test($scope.pwd))) {
            alert("密码长度少于6位");
            return;
        }
        fac.post("登录", "customer/" + $scope.phone + "/" + $scope.pwd + "Login_Native", function (data) {
            //debugger;
            sytdapp.LoggedUser.set(data);
            //$location.path("/");
            fac.redirect2Index();
        })
    }
    $scope.forgetpwd = function () {
        $location.path("/forgetpwd");
    }
    $scope.register = function () {
        $location.path("/register");
    }
}]);
//注册
app.controller("RegisterController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("注册", function () {
        //fac.accessStatistics("#/register");
        //$scope.back = function () {
        //    $location.path("/login");
        //}
        $scope.sendstatus = 0;
        $scope.yzmstatus = 1;
        $scope.getyzm = function () {
            if (!/^1[3|4|5|7|8]\d{9}$/.test($scope.phone)) {
                alert({
                    'tip': '手机号格式错误',
                });
                //alert("手机号格式错误");
            } else {
                if ($scope.yzmstatus) {
                    $scope.yzmstatus = 0;
                    var vcode_time = 30;
                    var vcode_id = $("#tel");
                    if ($(vcode_id).hasClass('on')) { } else {
                        $(vcode_id).addClass("on");
                        var msg_num = setInterval(function () {
                            $(vcode_id).find("a").html(vcode_time + "秒后重发");
                            vcode_time = vcode_time - 1
                            if (vcode_time == 0) {
                                clearInterval(msg_num);
                                $(vcode_id).find("a").html("重新获取");
                                $scope.yzmstatus = 1;
                                vcode_time = vcode_time;
                                $(vcode_id).removeClass("on");
                            }
                        }, 1000)
                    }
                    fac.get("获得验证码", "verification/Send?tel=" + $scope.phone, function (data) {
                        if (data.type) {
                            alert({
                                'tip': data.msg,
                            });
                            //alert(data.msg);
                            //$scope.yzmstatus = 0;
                            //var vcode_time = 30;
                            //var vcode_id = $("#tel");
                            //if ($(vcode_id).hasClass('on')) { } else {
                            //    $(vcode_id).addClass("on");
                            //    var msg_num = setInterval(function () {
                            //        $(vcode_id).find("a").html(vcode_time + "秒后重发");
                            //        vcode_time = vcode_time - 1
                            //        if (vcode_time == 0) {
                            //            clearInterval(msg_num);
                            //            $(vcode_id).find("a").html("重新获取");
                            //            $scope.yzmstatus = 1;
                            //            vcode_time = vcode_time;
                            //            $(vcode_id).removeClass("on");
                            //        }
                            //    }, 1000)
                            //}
                            $scope.sendstatus = 1;
                        } else {
                            alert({
                                'tip': data.msg,
                            });
                            //alert(data.msg);
                        }
                    })
                }
            }
        }
        $scope.register = function () {
            if ($scope.sendstatus) {
                if (!/^\d{6}$/.test($scope.yzm)) {
                    alert({
                        'tip': '手机验证码格式错误',
                    });
                    //alert("手机验证码格式错误");
                    return;
                }
                if (!(/\S{6,}/.test($scope.pwd))) {
                    alert({
                        'tip': '密码长度少于6位',
                    });
                    //alert("密码长度少于6位");
                    return;
                }
                if ($scope.pwd != $scope.pwd2) {
                    alert({
                        'tip': '两次密码不一致',
                    });
                    //alert("两次密码不一致");
                    return;
                }
                if ($scope.name == "" || $scope.name == null) {
                    alert({
                        'tip': '昵称不能为空',
                    });
                    //alert("昵称不能为空");
                    return;
                }
                //fac.get("验证验证码", "verification/verificationcode?tel=" + $scope.phone + "&code=" + $scope.yzm, function (data) {
                //    if (data == true) {
                //    } else {
                //        alert("手机验证码错误");
                //        return;
                //    }
                //})
                fac.get("注册", "customer/AddCustomer?mobile=" + $scope.phone +
                    "&nickname=" + $scope.name + "&password=" + $scope.pwd + "&verification=" + $scope.yzm, function (data) {
                        if (data == "成功") {
                            alert({
                                'tip': '注册成功',
                                confirmCallback: function () {
                                    AppConfigModel.doGoPageApp("#/login");
                                }
                            });
                            //alert("注册成功");
                            //$location.path("/login");
                            //fac.redirect2login();
                        } else if (data == "您是住建委用户,默认密码已发送至您手机,请登录后尽快修改") {
                            alert({
                                'tip': data,
                                confirmCallback: function () {
                                    AppConfigModel.doGoPageApp("#/login");
                                }
                            });
                            //alert(data);
                            //fac.redirect2login();
                        } else {
                            alert({
                                'tip': data,
                            });
                            //alert(data);
                        }
                    })
            } else {
                alert({
                    'tip': '请先发送验证码',
                });
                //alert("请先发送验证码");
            }
        }
    })
}]);
//忘记密码
app.controller("ForgetPwdController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("忘记密码", function () {
        //fac.accessStatistics("#/forgetpwd");
        //$scope.back = function () {
        //    $location.path("/login");
        //}
        $scope.sendstatus = 0;
        $scope.yzmstatus = 1;
        $scope.getyzm = function () {
            if (!/^1[3|4|5|7|8]\d{9}$/.test($scope.phone)) {
                alert({
                    'tip': '手机号格式错误',
                });
                //alert("手机号格式错误");
            } else {
                if ($scope.yzmstatus) {
                    $scope.yzmstatus = 0;
                    var vcode_time = 30;
                    var vcode_id = $("#tel");
                    if ($(vcode_id).hasClass('on')) { } else {
                        $(vcode_id).addClass("on");
                        var msg_num = setInterval(function () {
                            $(vcode_id).find("a").html(vcode_time + "秒后重发");
                            vcode_time = vcode_time - 1
                            if (vcode_time == 0) {
                                clearInterval(msg_num);
                                $(vcode_id).find("a").html("重新获取");
                                $scope.yzmstatus = 1;
                                vcode_time = vcode_time;
                                $(vcode_id).removeClass("on");
                            }
                        }, 1000)
                    }
                    fac.get("获得验证码", "verification/Send?tel=" + $scope.phone, function (data) {
                        if (data.type) {
                            alert({
                                'tip': data.msg,
                            });
                            //alert(data.msg);
                            //$scope.yzmstatus = 0;
                            //var vcode_time = 30;
                            //var vcode_id = $("#tel");
                            //if ($(vcode_id).hasClass('on')) { } else {
                            //    $(vcode_id).addClass("on");
                            //    var msg_num = setInterval(function () {
                            //        $(vcode_id).find("a").html(vcode_time + "秒后重发");
                            //        vcode_time = vcode_time - 1
                            //        if (vcode_time == 0) {
                            //            clearInterval(msg_num);
                            //            $(vcode_id).find("a").html("重新获取");
                            //            $scope.yzmstatus = 1;
                            //            vcode_time = vcode_time;
                            //            $(vcode_id).removeClass("on");
                            //        }
                            //    }, 1000)
                            //}
                            $scope.sendstatus = 1;
                        } else {
                            alert({
                                'tip': data.msg,
                            });
                            //alert(data.msg);
                        }
                    })
                }
            }
        }
        $scope.repwd = function () {
            if ($scope.sendstatus) {
                if (!(/\S{6,}/.test($scope.newpwd))) {
                    alert({
                        'tip': '密码长度少于6位',
                    });
                    //alert("密码长度少于6位");
                    return;
                }
                if ($scope.newpwd != $scope.newpwd2) {
                    alert({
                        'tip': '两次密码输入不一致',
                    });
                    //alert("两次密码输入不一致");
                    return;
                }
                fac.get("重置密码", "customer/Resetpassword?mobile=" + $scope.phone + "&newpwd=" + $scope.newpwd + "&verification=" + $scope.yzm, function (data) {
                    if (data == true) {
                        //alert("重置密码成功");
                        sytdapp.LoggedUser.clear();
                        alert({
                            'tip': '重置密码成功',
                            confirmCallback: function () {
                                AppConfigModel.doGoPageApp("#/login");
                            }
                        });
                        //$location.path("/login");
                        //fac.redirect2login();
                    } else {
                        alert({
                            'tip': '重置密码失败',
                        });
                        //alert("重置密码失败");
                    }
                })
            } else {
                alert({
                    'tip': '请先发送验证码',
                });
                //alert("请先发送验证码");
            }
        }
    });
}]);
//等额本金计算器
app.controller("PrincipalController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("等额本金", function () {
        fac.accessStatistics("#/principle");
        //$scope.back = function () {
        //    history.back();
        //}
    });
}]);
//等额本息计算器
app.controller("InterestController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("等额本息", function () {
        fac.accessStatistics("#/interest");
        //$scope.back = function () {
        //    history.back();
        //}
    });
}]);
//公积金计算器
app.controller("HousingFundController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("公积金额度", function () {
        fac.accessStatistics("#/housingfund");
        //$scope.back = function () {
        //    history.back();
        //}
    });
}]);
//利率说明
app.controller("RateController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("利率说明", function () {
        //fac.accessStatistics("#/rate");
        //$scope.back = function () {
        //    history.back();
        //}
    });
}]);
//企业列表
app.controller("EnterpriceLController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {
    fac.deviceready("企业资质", function () {
        fac.accessStatistics("#/enterpricel");
        //$scope.back = function () {
        //    history.back();
        //}
        $scope.page = 1;
        $scope.rows = 10;
        window.localStorage.setItem("companyname", "");
        fac.get("企业列表", "Enterprise/GetMoreByValue?value=" + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            $scope.list = data;
        })
        $scope.getdata = function () {
            $scope.page++;
            var companyname = window.localStorage.getItem("companyname");
            fac.get("企业列表", "Enterprise/GetMoreByValue?value=" + companyname + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                $scope.list = $scope.list.concat(data);
            })
        }
        $scope.find = function () {
            if ($scope.name == undefined || $scope.name == null) {
                $scope.name = "";
            }
            window.localStorage.setItem("companyname", $scope.name);
            fac.get("企业搜索", "Enterprise/GetMoreByValue?value=" + $scope.name + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                $scope.list = data;
            })
        }
        $scope.clean = function () {
            $scope.name = "";
        }
        $scope.detail = function (id) {
            $location.path("/enterpriced/" + id);
        }
    });
}]);
//企业详细
app.controller("EnterpriceDController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {
    fac.deviceready("企业详细", function () {
        //fac.accessStatistics("#/enterpriced");
        //$scope.back = function () {
        //    history.back();
        //}
        fac.get("企业详细", "Enterprise/Getinfo/" + $routeParams.id, function (data) {
            $scope.info = data;
            if (data.EnterpriseType == null) {
                $("#fuhao").hide();
            }
        })
    });

}]);
//企业信用列表
app.controller("EnterpriceCreditLController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("企业信用", function () {
        fac.accessStatistics("#/enterpricecreditl");
        //$scope.back = function () {
        //    history.back();
        //}
        $scope.page = 1;
        $scope.rows = 10;
        window.localStorage.setItem("companycreditname", "");
        fac.get("企业信用", "Enterprise/GetMore?value=" + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            for (var i = 0; i < data.length; i++) {
                if (data[i].EVALUATIONLEVEL == "A") {
                    data[i].levela = true;
                } else if (data[i].EVALUATIONLEVEL == "B") {
                    data[i].levelb = true;
                } else if (data[i].EVALUATIONLEVEL == "C") {
                    data[i].levelc = true;
                } else if (data[i].EVALUATIONLEVEL == "D") {
                    data[i].leveld = true;
                }
            }
            $scope.list = data;
        })
        $scope.getdata = function () {
            $scope.page++;
            var companyname = window.localStorage.getItem("companycreditname");
            fac.get("企业信用", "Enterprise/GetMore?value=" + companyname + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                for (var i = 0; i < data.length; i++) {
                    if (data[i].EVALUATIONLEVEL == "A") {
                        data[i].levela = true;
                    } else if (data[i].EVALUATIONLEVEL == "B") {
                        data[i].levelb = true;
                    } else if (data[i].EVALUATIONLEVEL == "C") {
                        data[i].levelc = true;
                    } else if (data[i].EVALUATIONLEVEL == "D") {
                        data[i].leveld = true;
                    }
                }
                $scope.list = $scope.list.concat(data);
            })
        }
        $scope.find = function () {
            if ($scope.name == undefined || $scope.name == null) {
                $scope.name = "";
            }
            window.localStorage.setItem("companycreditname", $scope.name);
            fac.get("企业信用", "Enterprise/GetMore?value=" + $scope.name + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                $scope.list = data;
            })
        }
        $scope.clean = function () {
            $scope.name = "";
        }
    });
}]);
//项目列表
app.controller("ProjectLController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {
    fac.deviceready("工程项目", function () {
        fac.accessStatistics("#/projectl");
        //$scope.back = function () {
        //    history.back();
        //}
        $scope.page = 1;
        $scope.rows = 10;
        window.localStorage.setItem("projectname", "");
        fac.get("项目列表", "Project/GetMoreByName?name=" + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            $scope.list = data;
        })
        $scope.getdata = function () {
            $scope.page++;
            var projectname = window.localStorage.getItem("projectname");
            fac.get("项目列表", "Project/GetMoreByName?name=" + projectname + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                $scope.list = $scope.list.concat(data);
            })
        }
        $scope.find = function () {
            if ($scope.name == undefined || $scope.name == null) {
                $scope.name = "";
            }
            window.localStorage.setItem("projectname", $scope.name);
            fac.get("项目列表", "Project/GetMoreByName?name=" + $scope.name + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                $scope.list = data;
            })
        }
        $scope.clean = function () {
            $scope.name = "";
        }
        $scope.detail = function (id) {
            $location.path("/projectd/" + id);
        }
    });
}]);
//项目详细
app.controller("ProjectDController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {
    fac.deviceready("项目详情", function () {
        //fac.accessStatistics("#/projectd");
        //$scope.back = function () {
        //    history.back();
        //}
        fac.get("项目详细", "Project/Getinfo/" + $routeParams.id, function (data) {
            $scope.info = data;
        })
    });
}]);
//楼盘列表
app.controller("HouseLController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("楼盘信息", function () {
        fac.accessStatistics("#/housel");
        //MessageApp.showSearch();
        //$scope.back = function () {
        //    history.back();
        //}
        $scope.page = 1;
        $scope.rows = 10;
        window.localStorage.setItem("housename", "");
        fac.get("楼盘列表", "House/GetMoreByName?name=&area=&min=&max=" + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            $scope.list = data.LIST2;
            $scope.list2 = data.LIST1;
        })
        fac.get("区县", "RecordPoint/GetArea?id=&codetypeid=", function (data) {
            $scope.quxian = data;
        })
        $scope.getdata = function () {
            $scope.page++;
            var housename = window.localStorage.getItem("housename");
            var housemin = window.localStorage.getItem("housemin");
            var housemax = window.localStorage.getItem("housemax");
            var housearea = window.localStorage.getItem("housearea");
            fac.get("楼盘列表", "House/GetMoreByName?name=" + housename + "&area=" + housearea + "&min=" + housemin + "&max=" + housemax + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                $scope.list2 = $scope.list2.concat(data.LIST1);
            })
        }
        $scope.find1 = function () {
            if ($scope.name == undefined || $scope.name == null) {
                $scope.name = "";
            }
            window.localStorage.setItem("housename", $scope.name);
            fac.get("楼盘列表", "House/GetMoreByName?name=" + $scope.name + "&area=&min=&max=&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                $scope.list2 = data.LIST1;
            })
            $("#ty1").removeClass("active");
            $("#ty2").addClass("active");
            $(".page2").show()
            $(".page1").hide();
        };

        $scope.find2 = function () {
            if ($scope.area == undefined || $scope.area == null) {
                $scope.area = -1;
            }
            if ($scope.name2 == undefined || $scope.name2 == null) {
                $scope.name2 = "";
            }
            var price = $("#htype").val();
            var ar = price.split(",");
            $scope.page = 1;
            $scope.rows = 10;
            window.localStorage.setItem("housemin", ar[0]);
            window.localStorage.setItem("housemax", ar[1]);
            window.localStorage.setItem("housearea", $scope.area);
            fac.get("楼盘列表", "House/GetMoreByName?name=" + $scope.name2 + "&area=" + $scope.area + "&min=" + ar[0] + "&max=" + ar[1] + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                $scope.list2 = data.LIST1;
            })
            $("#ty1").removeClass("active");
            $("#ty2").addClass("active");
            $(".page2").show()
            $(".page1").hide();
        }
        var search = function () {
            $(".yincang").toggle();
            $("#ss").toggle();
        }
        fac.native_search(search);
        MessageApp.showSearch();
        $scope.clean = function () {
            $scope.name = "";
        }
        $scope.detail = function (id) {
            $location.path("/housed/" + id);
        }
    });
}]);
//楼盘详细
app.controller("HouseDController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {
    fac.deviceready("楼盘详细", function () {
        //fac.accessStatistics("#/housed");
        MessageApp.showTextNull();
        fac.get("楼盘详细", "House/Getinfo/" + $routeParams.id, function (data) {
            $scope.info = data;
            if (data.HSOLDPRICE == 0) {
                $("#HSOLDPRICE").hide();
            }
        })
    });
}]);
//房屋安全鉴定机构名录
app.controller("OrgController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("鉴定机构", function () {
        fac.accessStatistics("#/org");
        document.addEventListener("searchbutton", function () {

        }, false);
        window.localStorage.removeItem("Appraisal");
        window.localStorage.removeItem("Advisory");
        $scope.page1 = 1;
        $scope.rows1 = 10;
        $scope.page2 = 1;
        $scope.rows2 = 10;
        //取鉴定机构名录
        fac.get("鉴定机构名录", "AppraisalInstitutionsm/GetAppraisalPage?name=&pageIndex=" + $scope.page1 + "&pageSize=" + $scope.rows1, function (data) {
            $scope.list = data;
        })
        //取咨询联系方式
        fac.get("咨询联系方式", "AdvisoryContact/GetAdvisoryContactPage?name=&pageIndex=" + $scope.page2 + "&pageSize=" + $scope.rows2, function (data2) {
            $scope.list2 = data2;
        })
        $scope.getdata = function () {
            $scope.page1++;
            var name = window.localStorage.getItem("Appraisal");
            if (name == null || name == undefined) { name = "" };
            fac.get("鉴定机构名录", "AppraisalInstitutionsm/GetAppraisalPage?name=" + name + "&pageIndex=" + $scope.page1 + "&pageSize=" + $scope.rows1, function (data) {
                $scope.list = $scope.list.concat(data);
            })
        }
        $scope.getdata2 = function () {
            $scope.page2++;
            var name = window.localStorage.getItem("Advisory");
            fac.get("咨询联系方式", "AdvisoryContact/GetAdvisoryContactPage?name=" + name + "&pageIndex=" + $scope.page2 + "&pageSize=" + $scope.rows2, function (data2) {
                $scope.list2 = $scope.list2.concat(data2);
            })
        }
        var search = function () {
            $(".yincang").toggle();
            $("#ss").toggle();
        }
        fac.native_search(search);
        MessageApp.showSearch();
        $scope.find = function () {
            if ($(".qycx td a:eq(0)").hasClass("active")) {
                fac.get("鉴定机构名录", "AppraisalInstitutionsm/GetAppraisalPage?name=" + $scope.name + "&pageIndex=" + $scope.page1 + "&pageSize=" + $scope.rows1, function (data) {
                    $scope.list = data;
                    window.localStorage.setItem("Appraisal", $scope.name);
                })
            } else {
                fac.get("咨询联系方式", "AdvisoryContact/GetAdvisoryContactPage?name=" + $scope.name + "&pageIndex=" + $scope.page2 + "&pageSize=" + $scope.rows2, function (data2) {
                    $scope.list2 = data2;
                    window.localStorage.setItem("Advisory", $scope.name);
                })
            }
        }
        $scope.clean = function () {
            $scope.name = "";
        }
        $scope.detail = function (id) {
            $location.path("/orgd/" + id);
        }
    });
}]);
//房屋安全鉴定机构详情
app.controller("OrgDController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {
    fac.deviceready("机构详情", function () {
        //fac.accessStatistics("#/orgd");
        MessageApp.showTextNull();
        //取鉴定机构详情
        fac.get("鉴定机构名录", "AppraisalInstitutionsm/Get?id=" + $routeParams.id, function (data) {
            $scope.info = data;
        })
    });
}]);
//危房信息列表
app.controller("DHouseListController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("危房信息", function () {
        fac.accessStatistics("#/dhouselist");
        $scope.page = 1;
        $scope.rows = 10;
        window.localStorage.setItem("dhouseaddr", "");
        window.localStorage.setItem("dhousetype", "");
        window.localStorage.setItem("dhouselevel", "");
        window.localStorage.setItem("dhousearea", "");
        fac.get("危房信息", "DangerHouse/GetDangerHousePage?address=&area=&type=&level=&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            $scope.list = data;
        })
        fac.get("区县", "RecordPoint/GetArea?id=&codetypeid=", function (data) {
            $scope.quxian = data;
        })
        $scope.getdata = function () {
            $scope.page++;
            var dhouseaddr = window.localStorage.getItem("dhouseaddr");
            var dhousetype = window.localStorage.getItem("dhousetype");
            var dhouselevel = window.localStorage.getItem("dhouselevel");
            var dhousearea = window.localStorage.getItem("dhousearea");
            fac.get("危房信息", "DangerHouse/GetDangerHousePage?address=" + dhouseaddr + "&area=" + dhousearea + "&type=" + dhousetype + "&level=" + dhouselevel + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                $scope.list = $scope.list.concat(data);
            })
        }
        var search = function () {
            $(".qycx").add(".yincang").toggle();
        }
        fac.native_search(search);
        MessageApp.showSearch();
        $scope.find1 = function () {
            if ($scope.addr1 == undefined || $scope.addr1 == null) {
                $scope.addr1 = "";
            }
            $scope.page = 1;
            $scope.rows = 10;
            window.localStorage.setItem("dhouseaddr", $scope.addr1);
            fac.get("危房信息", "DangerHouse/GetDangerHousePage?address=" + $scope.addr1 + "&area=&type=&level=&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                $scope.list = data;
            });
        };
        $scope.find2 = function () {
            if ($scope.addr2 == undefined || $scope.addr2 == null) {
                $scope.addr2 = "";
            }
            if ($scope.area == undefined || $scope.area == null) {
                $scope.area = -1;
            }
            var type = $("#htype").val();
            var level = $("#result").val();
            $scope.page = 1;
            $scope.rows = 10;
            window.localStorage.setItem("dhouseaddr", $scope.addr2);
            window.localStorage.setItem("dhousetype", type);
            window.localStorage.setItem("dhouselevel", level);
            window.localStorage.setItem("dhousearea", $scope.area);
            fac.get("危房信息", "DangerHouse/GetDangerHousePage?address=" + $scope.addr2 + "&area=" + $scope.area + "&type=" + type + "&level=" + level + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                $scope.list = data;
            })
        }
        $scope.clean = function () {
            $scope.addr1 = "";
        }
        $scope.detail = function (id) {
            $location.path("/dhoused/" + id);
        }
    });
}]);
//危房详细
app.controller("DHouseDController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {
    fac.deviceready("危房详细", function () {
        MessageApp.showTextNull();
        //fac.accessStatistics("#/dhoused");
        fac.get("危房详细", "DangerHouse/Get/" + $routeParams.id, function (data) {
            $scope.info = data;
        })
    });
}]);
//办事指南
app.controller("GuideController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("办事指南", function () {
        //fac.accessStatistics("#/guide");
        //$scope.back = function () {
        //    $location.path("/");
        //}
        fac.get("办事指南专题", "ServiceGuide/GetTheme?servicetype=" + "个人办事", function (data) {
            $scope.types = data.value;
        })
        window.localStorage.setItem("guidetitle", "");
        window.localStorage.setItem("guidetype", "");
        window.localStorage.setItem("guidetheme", "");
        $scope.type = "";
        $scope.servicetype = "";
        $scope.page = 1;
        $scope.rows = 10;
        fac.get("办事指南", "ServiceGuide/GetServiceGuide?servicetype=&title=&theme=&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            $scope.list = data.value;
        })
        $scope.getdata = function () {
            var title = window.localStorage.getItem("guidetitle");
            var type = window.localStorage.getItem("guidetype");
            var theme = window.localStorage.getItem("guidetheme");
            $scope.page++;
            fac.get("办事指南", "ServiceGuide/GetServiceGuide?servicetype=" + type + "&title=" + title + "&theme=" + theme + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                if (data.value.length == 0) {
                } else {
                    $scope.list = $scope.list.concat(data.value);
                }
            })
        }
        $(".over-box td:eq(0)").click(function () {
            var type = $(".over-box td:eq(0) a").html();
            fac.get("办事指南专题", "ServiceGuide/GetTheme?servicetype=" + type, function (data) {
                $scope.types = data.value;
            })
        })
        $(".over-box td:eq(1)").click(function () {
            var type = $(".over-box td:eq(1) a").html();
            fac.get("办事指南专题", "ServiceGuide/GetTheme?servicetype=" + type, function (data) {
                $scope.types = data.value;
            })
        })
        $scope.find = function () {
            if ($scope.name == null) $scope.name = "";
            var type = $(".dropdown").val();
            $scope.type = type;
            window.localStorage.setItem("guidetheme", type);
            window.localStorage.setItem("guidetitle", $scope.name);
            if ($(".over-box td:eq(1) .active").html() == undefined) {
                var servicetype = $(".over-box td:eq(0) a").html();
                $scope.servicetype = servicetype;
                window.localStorage.setItem("guidetype", servicetype);
            } else {
                var servicetype = $(".over-box td:eq(1) a").html();
                $scope.servicetype = servicetype;
                window.localStorage.setItem("guidetype", servicetype);
            }
            $scope.page = 1;
            $scope.rows = 10;
            fac.get("办事指南", "ServiceGuide/GetServiceGuide?servicetype=" + servicetype + "&title=" + $scope.name + "&theme=" + type + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                $scope.list = data.value;
            })
        }
        $scope.detail = function (id) {
            $location.path("/guidedetail/" + id);
        }
    });
}]);
//办事指南详细
app.controller("GuideDController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {
    fac.deviceready("办事详细", function () {
        //fac.accessStatistics("#/guidedetail");
        //$scope.back = function () {
        //    $location.path("/guide");
        //}
        fac.get("办事指南详细", "ServiceGuide/GetSingle?id=" + $routeParams.id, function (data) {
            $scope.info = data.value;
            $("#img2").html(data.value.BLCL)
            $("#img3").html(data.value.BLTJ)
            $("#img1").html(data.value.ZBXX)
        })
    });
}]);
//专题集合
app.controller("SpecialkController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("专题", function () {
        //fac.accessStatistics("#/special");
        //$scope.back = function () {
        //    $location.path("/");
        //}
        $scope.page = 1;
        $scope.rows = 10;
        fac.get("专题集合", "Special/Get?pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            $scope.list = data;
        })
        $scope.getdata = function () {
            $scope.page++;
            fac.get("专题集合", "Special/Get?pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                if (data.value.length == 0) {
                } else {
                    $scope.list = $scope.list.concat(data);
                }
            })
        }
        $scope.detail = function (id) {
            $location.path("/speciall/" + id);
        }
    });
}]);
//专题列表
app.controller("SpeciallController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {
    fac.deviceready("专题文章", function () {
        //fac.accessStatistics("#/speciall");

        $scope.page = 1;
        $scope.rows = 10;
        fac.get("专题列表", "SpecialD/Get?cid=" + $routeParams.id + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
            for (var i = 0; i < data.length; i++) {
                if (data[i].COVERIMAGEURL == null) {
                    data[i].isimg = false;
                } else {
                    data[i].isimg = true;
                }
            }
            $scope.list = data;
        })
        $scope.getdata = function () {
            $scope.page++;
            fac.get("专题列表", "SpecialD/Get?cid=" + $routeParams.id + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows, function (data) {
                if (data.value.length == 0) {
                } else {
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].COVERIMAGEURL == null) {
                            data[i].isimg = false;
                        } else {
                            data[i].isimg = true;
                        }
                    }
                    $scope.list = $scope.list.concat(data);
                }
            })
        }
        $scope.detail = function (id, type) {
            if (type == 1) {
                fac.get("专题外链", "SpecialD/Getsingle?cid=" + id, function (data) {
                    if (data.TITLE.length > 6) {
                        var Title = data.TITLE.substr(0, 6) + "..."
                    }
                    window.location = "ifr.html?u=" + escape(data.CONTENT) + "&t=" + escape(Title);
                })
            } else {
                $location.path("/speciald/" + id);
            }
        }
    });
}]);
//专题详细
app.controller("SpecialdController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {
    fac.deviceready("专题详细", function () {
        //fac.accessStatistics("#/speciald");
        //$scope.back = function () {
        //    history.back();
        //}
        fac.get("专题详细", "SpecialD/Getsingle?cid=" + $routeParams.id, function (data) {
            if (data.TITLE.length > 6) {
                var Title = data.TITLE.substr(0, 6) + "..."
            }
            $(".container-title-main").html(Title);
            $("#content").html(data.CONTENT);
        })
    })
}]);
//公积金详细
app.controller("GJJQUERYController", ["$scope", "$http", "$location", "$routeParams", "zjwappFactory", function ($scope, $http, $location, $routeParams, fac) {
    fac.deviceready("公积金", function () {
        //fac.accessStatistics("#/gjjquery");
        if ($routeParams.type == 1) {
            fac.get("公积金详细", "GJJ/Query?certinum=" + $routeParams.name, function (data) {
                //window.localStorage.setItem("certinum", $routeParams.name);
                window.localStorage.setItem("gjjlastbal", data.bal);
                var now = new Date();
                var date = now.getFullYear().toString() + "-" + (now.getMonth() + 1).toString() + "-" + now.getDate().toString() + " " + now.getHours().toString() + ":" + now.getMinutes().toString() + ":" + now.getSeconds().toString();
                window.localStorage.setItem("gjjlasttime", date);
                $scope.info = data;
                if (data.freeuse1 == "正常") {
                    $("#zhengchang").show();
                } else {
                    $("#dongjie").show();
                }
            })
        } else if ($routeParams.type == 2) {
            fac.get("公积金详细", "GJJ/Query2?accnum=" + $routeParams.name, function (data) {
                //window.localStorage.setItem("accnum", $routeParams.name);
                window.localStorage.setItem("gjjlastbal", data.bal);
                var now = new Date();
                var date = now.getFullYear().toString() + "-" + (now.getMonth() + 1).toString() + "-" + now.getDate().toString() + " " + now.getHours().toString() + ":" + now.getMinutes().toString() + ":" + now.getSeconds().toString();
                window.localStorage.setItem("gjjlasttime", date);
                $scope.info = data;
                if (data.freeuse1 == "正常") {
                    $("#zhengchang").show();
                } else {
                    $("#dongjie").show();
                }
            })
        }
    })
}]);
//公积金查询
app.controller("GJJCXController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {

    fac.deviceready("公积金", function () {
        fac.accessStatistics("#/gjjcx");

        $scope.query = function () {
            if ($("#f_left").hasClass("active")) {
                if ($scope.cardnumber == null || $scope.cardnumber == undefined) {
                    alert({
                        'tip': '请输入身份证号',
                    });
                    //alert("请输入身份证号");
                    return;
                }
                if (!/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test($scope.cardnumber)) {
                    alert({
                        'tip': '身份证号格式错误',
                    });
                    //alert("身份证号格式错误");
                    return;
                }
                if ($scope.gjjpwd1 == null || $scope.gjjpwd1 == undefined) {
                    alert({
                        'tip': '请输入查询密码',
                    });
                    //alert("请输入查询密码");
                    return;
                }
                if (!/^\d{6}$/.test($scope.gjjpwd1)) {
                    alert({
                        'tip': '密码需为6位数字',
                    });
                    //alert("密码需为6位数字");
                    return;
                }
                fac.get("公积金登录", "GJJ/Login?pwd=" + $scope.gjjpwd1 + "&certinum=" + $scope.cardnumber, function (data) {
                    if (data == true) {
                        $location.path("/gjjquery/1/" + $scope.cardnumber);
                    } else {
                        $location.path("/gjjcx")
                    }
                })
            } else if ($("#f_right").hasClass("active")) {
                if ($scope.zhnumber == null || $scope.zhnumber == undefined) {
                    alert({
                        'tip': '请输入个人公积金帐号',
                    });
                    //alert("请输入个人公积金帐号");
                    return;
                }
                if ($scope.gjjpwd2 == null || $scope.gjjpwd2 == undefined) {
                    alert({
                        'tip': '请输入查询密码',
                    });
                    //alert("请输入查询密码");
                    return;
                }
                if (!/^\d{6}$/.test($scope.gjjpwd2)) {
                    alert({
                        'tip': '密码需为6位数字',
                    });
                    //alert("密码需为6位数字");
                    return;
                }
                fac.get("公积金登录2", "GJJ/Login2?pwd=" + $scope.gjjpwd2 + "&accnum=" + $scope.zhnumber, function (data) {
                    if (data == true) {
                        $location.path("/gjjquery/2" + $scope.zhnumber);
                    } else {
                        $location.path("/gjjcx")
                    }
                })
            }
        }
    })
}]);
//物业专项维修资金
app.controller("WYWXJJController", ["$scope", "$sce", "$http", "$location", "zjwappFactory", function ($scope, $sce, $http, $location, fac) {
    fac.deviceready("物业维修基金", function () {
        fac.accessStatistics("#/wywxjj");
        $scope.trustSrc = $sce.trustAs($sce.RESOURCE_URL, "http://www.nbjs.gov.cn/gb/bmfw/wywxzjcx.htm");
    });
}]);
//房屋征收公开
app.controller("FWZSController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("房屋征收", function () {
        fac.accessStatistics("#/fwzsgk");
    });
}]);
//项目概括
app.controller("FXMGKController", ["$scope", "$sce", "$http", "$routeParams", "$location", "zjwappFactory", function ($scope, $sce, $http, $routeParams, $location, fac) {
    fac.deviceready("项目概括", function () {
        $scope.trustSrc1 = $sce.trustAs($sce.RESOURCE_URL, "http://nbzs.org.cn/Wechat/ProjectHandler.ashx?action=view");
    });
}]);
//征收决定
app.controller("FZSJDController", ["$scope", "$sce", "$http", "$routeParams", "$location", "zjwappFactory", function ($scope, $sce, $http, $routeParams, $location, fac) {
    fac.deviceready("征收决定", function () {
        $scope.trustSrc2 = $sce.trustAs($sce.RESOURCE_URL, "http://nbzs.org.cn/Wechat/ProjectHandler.ashx?action=edpage");
    });
}]);
//项目公告
app.controller("FXMGGController", ["$scope", "$sce", "$http", "$routeParams", "$location", "zjwappFactory", function ($scope, $sce, $http, $routeParams, $location, fac) {
    fac.deviceready("项目公告", function () {
        $scope.trustSrc3 = $sce.trustAs($sce.RESOURCE_URL, "http://nbzs.org.cn/Wechat/BulletHandler.ashx");
    });
}]);
//办事指南
app.controller("FBSZNController", ["$scope", "$sce", "$http", "$routeParams", "$location", "zjwappFactory", function ($scope, $sce, $http, $routeParams, $location, fac) {
    fac.deviceready("办事指南", function () {
        $scope.trustSrc4 = $sce.trustAs($sce.RESOURCE_URL, "http://nbzs.org.cn/Wechat/GuideHandler.ashx");
    });
}]);
//政策法规
app.controller("FZCFGController", ["$scope", "$sce", "$http", "$routeParams", "$location", "zjwappFactory", function ($scope, $sce, $http, $routeParams, $location, fac) {
    fac.deviceready("政策法规", function () {
        $scope.trustSrc5 = $sce.trustAs($sce.RESOURCE_URL, "http://nbzs.org.cn/Wechat/PolicyHandler.ashx");
    });
}]);
//调查结果
app.controller("FDCJGController", ["$scope", "$sce", "$http", "$routeParams", "$location", "zjwappFactory", function ($scope, $sce, $http, $routeParams, $location, fac) {
    fac.deviceready("调查结果", function () {
        $scope.trustSrc6 = $sce.trustAs($sce.RESOURCE_URL, "http://nbzs.org.cn/Wechat/FamilysHandler.ashx");
    });
}]);
//评估结果
app.controller("FPGJGController", ["$scope", "$sce", "$http", "$routeParams", "$location", "zjwappFactory", function ($scope, $sce, $http, $routeParams, $location, fac) {
    fac.deviceready("评估结果", function () {
        $scope.trustSrc7 = $sce.trustAs($sce.RESOURCE_URL, "http://nbzs.org.cn/Wechat/EstimateHandler.ashx");
    });
}]);
//补偿结果
app.controller("FBCJGController", ["$scope", "$sce", "$http", "$routeParams", "$location", "zjwappFactory", function ($scope, $sce, $http, $routeParams, $location, fac) {
    fac.deviceready("补偿结果", function () {
        $scope.trustSrc8 = $sce.trustAs($sce.RESOURCE_URL, "http://nbzs.org.cn/Wechat/ContractsHandler.ashx");
    });
}]);
//行政审批结果
app.controller("XZSPJGController", ["$scope", "$sce", "$http", "$location", "zjwappFactory", function ($scope, $sce, $http, $location, fac) {
    fac.deviceready("行政审批", function () {
        fac.accessStatistics("#/xzspjg");
        //$scope.trustSrc = $sce.trustAs($sce.RESOURCE_URL, "http://www.zjzwfw.gov.cn/zjzw/item/list/sp_index.do?from=dept&webid=16&deptid=002939927");
        $scope.xndt = function () {
            $location.path("/xndt");
        }
        $scope.guide = function () {
            $location.path("/guide");
        }
    });
}]);
//虚拟大厅
app.controller("XNDTController", ["$scope", "$sce", "$http", "$location", "zjwappFactory", function ($scope, $sce, $http, $location, fac) {
    fac.deviceready("虚拟大厅", function () {
        $scope.trustSrc = $sce.trustAs($sce.RESOURCE_URL, "https://720yun.com/t/a1728ja5cua?pano_id=291831");
    });
}]);
//我有话说
app.controller("WYHSController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("我有话说", function () {
        $scope.back = function () {
            if ($(".page2").hasClass("active")) {
                $(".page2").hide().removeClass("active");
                $(".page1").show().addClass("active");
            } else if ($(".page3").hasClass("active")) {
                $(".page3").hide().removeClass("active");
                $(".page2").show().addClass("active");
            } else {
                fac.trackRecord.back($location);
            }
        }
        $scope.pageClass = "zjw-slide"
        fac.accessStatistics("#/wyhs");
        $scope.next = function () {
            if ($scope.name == null || $scope.name == undefined) {
                alert({
                    'tip': '请输入姓名',
                });
                //alert("请输入姓名");
                return;
            }
            if ($("#sex").val() == -1) {
                alert({
                    'tip': '请选择性别',
                });
                //alert("请选择性别");
                return;
            }
            if ($scope.tel == null || $scope.tel == undefined) {
                alert({
                    'tip': '请输入联系电话',
                });
                //alert("请输入联系电话");
                return;
            }
            if (!/^1[3|4|5|7|8]\d{9}$/.test($scope.tel)) {
                alert({
                    'tip': '手机号格式错误',
                });
                //alert("手机号格式错误");
                return;
            }
            if ($scope.email == null || $scope.email == undefined) {
                alert({
                    'tip': '请输入联系邮箱',
                });
                //alert("请输入联系邮箱");
                return;
            }
            if (!/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test($scope.email)) {
                alert({
                    'tip': '邮箱格式错误',
                });
                //alert("邮箱格式错误");
                return;
            }
            $(".page1").hide().removeClass("active");
            $(".page2").show().addClass("active");
        }
        $scope.next2 = function () {
            if ($("#cansee").val() == -1) {
                alert({
                    'tip': '请选择是否在网上公开',
                });
                //alert("请选择是否在网上公开");
                return;
            }
            if ($scope.theme == null || $scope.theme == undefined) {
                alert({
                    'tip': '请输入主题',
                });
                //alert("请输入主题");
                return;
            }
            if ($scope.theme.length > 20) {
                alert({
                    'tip': '主题过长，应小于20字',
                });
                //alert("主题过长，应小于20字");
                return;
            }
            if ($scope.remark == null || $scope.remark == undefined) {
                alert({
                    'tip': '请输入备注',
                });
                //alert("请输入备注");
                return;
            }
            if ($scope.remark.length > 100) {
                alert({
                    'tip': '备注过长，应小于100字',
                });
                //alert("备注过长，应小于100字");
                return;
            }
            var url = $("#wyhsfj img").attr("url");
            //if (url == null || url == undefined) {
            //    alert({
            //        'tip': '请上传附件',
            //    });
            //    //alert("请上传附件");
            //    return;
            //}
            if ($scope.sendstatus) {

            } else {
                alert({
                    'tip': '请先发送验证码',
                });
                //alert("请先发送验证码");
                return;
            }
            if ($scope.yzm == null || $scope.yzm == undefined) {
                alert({
                    'tip': '验证码不能为空',
                });
                //alert("验证码不能为空");
                return;
            }
            $scope.sexname = $("#sex").val() == 0 ? "男" : "女";
            $scope.gongkai = $("#cansee").val() == 0 ? "否" : "是";
            $(".page2").hide().removeClass("active");
            $(".page3").show().addClass("active");
        }
        $scope.sendstatus = 0;
        $scope.yzmstatus = 1;
        $scope.getyzm = function () {
            if (!/^1[3|4|5|7|8]\d{9}$/.test($scope.tel2)) {
                alert({
                    'tip': '手机号格式错误',
                });
                //alert("手机号格式错误");
            } else {
                if ($scope.yzmstatus) {
                    $scope.yzmstatus = 0;
                    var vcode_time = 30;
                    var vcode_id = $("#tel");
                    if ($(vcode_id).hasClass('on')) { } else {
                        $(vcode_id).addClass("on");
                        var msg_num = setInterval(function () {
                            $(vcode_id).find("a").html(vcode_time + "秒后重发");
                            vcode_time = vcode_time - 1
                            if (vcode_time == 0) {
                                clearInterval(msg_num);
                                $(vcode_id).find("a").html("重新获取");
                                $scope.yzmstatus = 1;
                                vcode_time = vcode_time;
                                $(vcode_id).removeClass("on");
                            }
                        }, 1000)
                    }
                    //调用“主任信箱”短信接口
                    fac.get("获得验证码", "OutMessage/SeedMSG?userMobile=" + $scope.tel2, function (data) {
                        if (data.level == 0) {
                            alert({
                                'tip': '验证码发送成功',
                            });
                            //alert("手机验证码发送成功");
                            //$scope.yzmstatus = 0;
                            //var vcode_time = 30;
                            //var vcode_id = $("#tel");
                            //if ($(vcode_id).hasClass('on')) { } else {
                            //    $(vcode_id).addClass("on");
                            //    var msg_num = setInterval(function () {
                            //        $(vcode_id).find("a").html(vcode_time + "秒后重发");
                            //        vcode_time = vcode_time - 1
                            //        if (vcode_time == 0) {
                            //            clearInterval(msg_num);
                            //            $(vcode_id).find("a").html("重新获取");
                            //            $scope.yzmstatus = 1;
                            //            vcode_time = vcode_time;
                            //            $(vcode_id).removeClass("on");
                            //        }
                            //    }, 1000)
                            //}
                            $scope.sendstatus = 1;
                        } else {
                            alert({
                                'tip': '验证码发送失败',
                            });
                            //alert("手机验证码发送失败");
                        }
                    })
                }
            }
        }
        $scope.upload = function () {
            //$("#imgbox").html('<div class="img-box" id="wyhsfj"><img src="http://img1.com" style="width:120px;height:120px;" url="http://img1.com"><em id="del"><a onclick="f_del()"></a></em></div>');
            FileUploadApp.doFileUploadApp(
                //"http://fileupload.openxt.com/ueditor/controller.ashx",
                "http://120.26.232.187:10086/ueditor/controller.ashx",
                {
                    action: "uploadfile"
                }, "*", false, function (str) {
                    var data = JSON.parse(str);
                    if (data.state == "SUCCESS") {
                        var url = data.prefix + data.url;
                        var type = data.url.split(".");
                        var s = type[type.length - 1];
                        if (s == "jpg" || s == "png" || s == "jpeg" || s == "bmp" || s == "gif") {
                            //var url = "http://fileupload.openxt.com/" + data.url;
                            $("#imgbox").html('<div class="img-box" id="wyhsfj"><img src=' + url + ' style="width:120px;height:120px;" url=' + url + '><em id="del"><a onclick="f_del()"></a></em></div>');
                        } else {
                            $("#imgbox").html('<div class="img-box" id="wyhsfj"><img src="/Content/images/timg.jpg" style="width:120px;height:120px;" url=' + url + '><em id="del"><a onclick="f_del()"></a></em></div>');
                        }
                    } else {
                        alert(data.state);
                    }
                });
        }
        $scope.submit = function () {
            var param = {
                txtname: $scope.name,
                sex: $("#sex").val(),
                txttel: $scope.tel,
                txteml: $scope.email,
                txttitle: $scope.theme,
                txtdes: $scope.remark,
                user_tel: $scope.tel2,
                MobileCode: $scope.yzm,
                cansee: $("#cansee").val(),
                fileurl: $("#wyhsfj img").attr("url"),
            }
            var model = JSON.stringify(param)
            fac.post("我有话说", "OutMessage/Publish", function (data) {
                if (data.level == 0) {
                    alert({
                        'tip': '提交成功',
                    });
                    //alert("发送成功");
                    fac.trackRecord.back($location);
                } else {
                    alert({
                        'tip': '提交失败',
                    });
                    //alert("发送失败");
                }
            }, {
                data: {
                    "models": model
                }
            })
        }
    })
}]);
//绑定宽易帐号
app.controller("BindKYController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    //$scope.back = function () {
    //    $location.path("/");
    //}
    //fac.accessStatistics("#/bingky");
    $scope.bind = function () {
        if ($scope.name == null || $scope.name == undefined) {
            alert("请输入安全系统帐号");
            return;
        }
        if ($scope.pwd == null || $scope.pwd == undefined) {
            alert("请输入密码");
            return;
        }
        fac.get("绑定宽易帐号", "Customer/bindky?name=" + $scope.name + "&pwd=" + $scope.pwd, function (data) {
            if (data == true) {
                alert("绑定成功");
                $location.path("/")
            } else {
                alert("绑定失败");
            }
        });
    }
}]);
//我的收藏
app.controller("MyFavController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("我的收藏", function () {
        //fac.accessStatistics("#/myfav");
        document.addEventListener("searchbutton", function () {
        }, false);
        $scope.page1 = 1;
        $scope.rows1 = 10;
        $scope.page2 = 1;
        $scope.rows2 = 10;
        //取我的新闻收藏
        fac.get("我的新闻", "News/GetMyNews?pageIndex=" + $scope.page1 + "&pageSize=" + $scope.rows1, function (data) {
            for (var i = 0; i < data.length; i++) {
                if (data[i].SHOW_TITLE == null) {
                    data[i].isimg = false;
                } else {
                    data[i].isimg = true;
                    //data[i].newslist[j].T_NEWS.SHOW_TITLE = "http://bs.nbjs.gov.cn/Upload/image/20150430/QQ%E6%88%AA%E5%9B%BE201504300845246356598038555482075177268.png"
                }
            }
            $scope.list = data;
        })
        //取我的公告收藏
        fac.get("我的公告", "Notice/GetMyNotice?pageIndex=" + $scope.page2 + "&pageSize=" + $scope.rows2, function (data2) {
            $scope.list2 = data2;
        })
        $scope.getdata = function () {
            $scope.page1++;
            fac.get("我的新闻", "News/GetMyNews?pageIndex=" + $scope.page1 + "&pageSize=" + $scope.rows1, function (data) {
                $scope.list = $scope.list.concat(data);
            })
        }
        $scope.getdata2 = function () {
            $scope.page2++;
            fac.get("我的公告", "Notice/GetMyNotice?pageIndex=" + $scope.page2 + "&pageSize=" + $scope.rows2, function (data2) {
                $scope.list2 = $scope.list2.concat(data2);
            })
        }
        $scope.detail = function (id) {
            $location.path("/newsdetail/" + id);
        }
        $scope.detail2 = function (id) {
            $location.path("/noticedetail/" + id);
        }
    });
}]);
//我的事项
app.controller("MyItemController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    fac.deviceready("我的事项", function () {
        //fac.accessStatistics("#/myitem");
        document.addEventListener("searchbutton", function () {
        }, false);
        //fac.get("客户数据模型", "DataModel/Get", function (data) {
        //    $scope.order = 0;
        //    for (var i = 0; i < data.length; i++) {
        //        if (data[i].ORDERSTATUS == "true") {
        //            $scope.order = $scope.order + 1;
        //            if (data[i].TYPE == 1) {
        //                $scope.listName1 = data[i].Name;
        //                $scope.page = 1;
        //                $scope.rows = 2;
        //                fac.get("客户巡查任务", "HousePatrol/GetMission?missioncode=&missiontype=" + 0 + "&pageIndex=" + $scope.page + "&pageSize=" + $scope.rows + "&houseid=", function (data) {
        //                    $scope.list = data.value;
        //                })
        //            } else if (data[i].TYPE == 2) {
        //                $scope.listName2 = data[i].Name;
        //                var acct1 = window.localStorage.getItem("accnum");
        //                var acct2 = window.localStorage.getItem("certinum");
        //                //fac.get("公积金", "GJJ/GetCustomerGJJ", function (data) {
        //                //    $scope.money = data.bal;
        //                //})
        //                if (acct2 != null) {
        //                    fac.get("公积金详细", "GJJ/Query?certinum=" + acct2, function (data) {
        //                        $scope.money = data.bal;
        //                    })
        //                } else if (acct1 != null) {
        //                    fac.get("公积金详细", "GJJ/Query2?accnum=" + acct1, function (data) {
        //                        $scope.money = data.bal;
        //                    })
        //                }
        //            }
        //        }
        //    }
        //    if ($scope.order == 0) {
        //        //$("#work1").hide();
        //        //$("#work2").hide();
        //    } else if ($scope.order == 1 && data[0].ORDERSTATUS == "true") {
        //        $("#work2").show();
        //    } else if ($scope.order == 1 && data[1].ORDERSTATUS == "true") {
        //        $("#work1").show();
        //    }
        //})
        //$scope.listName2 = data[i].Name;
        //var acct1 = window.localStorage.getItem("accnum");
        //var acct2 = window.localStorage.getItem("certinum");
        //fac.get("公积金", "GJJ/GetCustomerGJJ", function (data) {
        //    $scope.money = data.bal;
        //})
        //if (acct2 != null) {
        //    fac.get("公积金详细", "GJJ/Query?certinum=" + acct2, function (data) {
        //        $scope.money = data.bal;
        //    })
        //} else if (acct1 != null) {
        //    fac.get("公积金详细", "GJJ/Query2?accnum=" + acct1, function (data) {
        //        $scope.money = data.bal;
        //    })
        //}
        //$scope.detail = function (id) {
        //    $location.path("/patroltaskd/" + id);
        //}
        //$scope.shezhi = function () {
        //    $location.path("uptmk")
        //}
        var lastbal = window.localStorage.getItem("gjjlastbal");
        var lasttime = window.localStorage.getItem("gjjlasttime")
        if (lastbal == null && lasttime == null) {
//            $location.path("/gjjcx");
        } else {
            $scope.money = lastbal;
            $scope.lasttime = lasttime;
        }
        $scope.gjjcx = function () {
            $location.path("/gjjcx");
        }
    });
}]);

app.controller("CSController", ["$scope", "$http", "$location", "zjwappFactory", function ($scope, $http, $location, fac) {
    var url = "http://120.26.232.187:10086/upload/file/20161207/6361669823146471774914682.xlsx";
    var type = url.split(".");
    var a = type.length;
    var s = type[a - 1];
    alert({
        'tip': '您是住建委用户,默认密码已发送至您手机,请登录后尽快修改',
        confirmCallback: function () {
            AppConfigModel.doGoPageApp("#/login");
        }
    });

    //$("#file").html("<img src=\"/Content/images/timg.jpg\" style=\"width:120px;height:120px;\" url=" + url + ">");
    //var content = "<p align='center'><img height='155' alt='' width='208' src='/Affix/Article/20071105094355208x155.gif' /></p><p align='left'>&nbsp;&nbsp;&nbsp; 金秋十月，繁花似锦，高朋云集。第十二届中国宁波国际住宅产品博览会开幕招待会昨晚在南苑饭店隆重举行。市委副书记、市长毛光烈宣布住博会开幕。 <br />&nbsp;&nbsp;&nbsp;&nbsp;出席招待会的领导和嘉宾有：建设部原党组副书记、副部长刘志峰，建设部住宅产业化促进中心主任陆克华，建设部住宅与房地产业司副司长张小宏，省建设厅党组成员、省纪委驻建设厅纪检组组长周松林，中国城市规划设计研究院院长李晓江，中国城市规划设计研究院总规划师杨葆军，澳大利亚新南威尔士大学教授乔恩&middot;兰，美国加州大学洛杉矶分校教授安娜斯黛西娅，德国CIM专家菲沃克等，以及宁波市委副书记郭正伟、副市长苏利冕、市政协副主席常敏毅等。 <br />&nbsp;&nbsp;&nbsp;&nbsp;本届住博会以&nbsp;&ldquo;倡导绿色住宅，建设人居名城&rdquo;为主题，全面展示住宅产业产品最新成果和发展趋势，同时将举办宁波市&nbsp;&ldquo;中提升&rdquo;战略实施一周年回顾活动、2007年国际城市规划学术委员会年会、2007博鳌&middot;21世纪房地产论坛等十余项重要活动。展会将充分发挥宣传贯彻国家住宅产业政策的示范作用、信息和商机的传递作用，以及住宅产业发展的导向作用。 <br />&nbsp;&nbsp;&nbsp;&nbsp;刘志峰对本届住博会的开幕表示热烈祝贺。他说，住博会是反映住宅产业最新成就和未来趋势的一个平台，对促进住宅产业持续、稳定、健康发展起着积极作用。宁波是一座充满生机和活力的城市，又是一座有巨大发展潜力的港口城市。宁波商贸发达，基础产业雄厚，会展业迅速崛起，为举办住博会创造了优越条件。相信在宁波市委、市政府的高度重视和大力支持下，宁波市住宅产业现代化将迈上一个新台阶。 <br />&nbsp;&nbsp;&nbsp;&nbsp;苏利冕说，宁波将以更加扎实的举措，努力推进住宅产业持续、稳定、健康发展，全力支持住博会的举办。通过住博会的平台，加强与海内外同行的交流与合作，吸引海内外客商前来投资建设。&nbsp;</p><p align='center'><img alt='' border='0' src='http://www.nbjs.gov.cn/upload/2007_11/20071105094415.gif' />&nbsp;<img alt='' border='0' src='http://www.nbjs.gov.cn/upload/2007_11/20071105094431.gif' /></p><p align='center'><img alt='' border='0' src='http://www.nbjs.gov.cn/upload/2007_11/20071105101522.gif' />&nbsp;<img alt='' border='0' src='http://www.nbjs.gov.cn/upload/2007_11/20071105094453.gif' /></p>"
    //content = content.replace(/width='\d+'/, "width='100%'");
    //content = content.replace(/height='\d+'/, "height='auto'");
    //content = content.replace("src='/", "src='http://www.nbjs.gov.cn/");
    //content = content.replace(/img style=".*px"\s/, "img style='width:100%;height:auto' ")
    //$scope.back = function () {
    //    $location.path("/");
    //}
    //$scope.cs = function () {
    //    $http.post("http://61.153.144.78:10080/GjjQuery", { models: "aaa" }).success(function (data) {
    //        alert(data)
    //    });
    //}
    //$scope.baidu = function () {
    //    $http.post("http://www.baidu.com").success(function (data) {
    //        alert(data)
    //    });
    //}
    //$scope.dingyue = function () {
    //    //$http.post()
    //}
}]);


//数据工厂
app.factory("zjwappFactory", ['$http', '$location',
    function ($http, $location) {
        ///异常统一处理方法
        var errorCallback = function (data, status, headers, config) {
            //debugger;
            switch (status) {
                case 401://登录失效
                    sytdapp.LoggedUser.clear();
                    //$location.path("/login");
                    obj.redirect2login();
                    break;
                case 404:
                    break;
            }

            //可以根据状态扩展
            if (data !== null && typeof data === 'object') {
                alert(data.Message);
            } else {
                alert("网络不通/服务停止");
            }
        }

        var backQueue2 = {
        };
        (function (d) {
            d.mylocalStorage = {
                indexDOM: {
                    path: "/"
                },
                backQueue: {
                    get: function () {//recount(是否重新计数)：
                        var val = window.localStorage.getItem("TrackRecord_Queue");
                        var result = new Array();
                        if (val !== undefined && val !== null && typeof val === "string" && val.length > 0) {
                            //result = val.split(",");
                            result = val.split("$__$");
                        }
                        return result;
                    },
                    set: function (arr, keyCtrl, path) {
                        var _index = -1;
                        for (var i = 0; i < arr.length; i++) {
                            var ele = arr[i];
                            var items = ele.split("|");
                            if (keyCtrl === items[0]) {
                                _index = i;
                                break;
                            }
                        }
                        if (_index === -1) {
                        } else {
                            while (arr.length > _index) {
                                arr.pop();
                            }
                        }
                        var val = keyCtrl + "|" + path;
                        arr.push(val);
                        //window.localStorage.setItem("TrackRecord_Queue", arr);
                        var arrstr = "";
                        for (var i = 0; i < arr.length; i++) {
                            arrstr += (i == 0 ? "" : "$__$") + arr[i];
                        }
                        window.localStorage.setItem("TrackRecord_Queue", arrstr);
                    },
                    clear: function () {
                        window.localStorage.removeItem("TrackRecord_Queue");
                    },
                    removeLast: function () {
                        //debugger;
                        var arr = d.mylocalStorage.backQueue.get();
                        var _length = arr.length - 2;
                        var path = "";
                        if (_length > -1) {
                            path = arr[_length].split("|")[1];
                            var _lpath = d.mylocalStorage.loginSubmit.get();
                            if (_lpath === path) {//移除自动跳转的
                                d.mylocalStorage.loginSubmit.clear();

                                if (_length === 0) {
                                    path = "/";
                                } else {
                                    path = arr[_length - 1].split("|")[1];
                                    arr.pop();
                                }
                            }
                            arr.pop();
                            arr.pop();
                        } else {
                            path = "/";
                        }
                        return path;
                    }
                },
                loginSubmit: {
                    get: function () {
                        return window.localStorage.getItem("TrackRecord_Queue_loginSubmitBack");
                    },
                    set: function (path) {
                        window.localStorage.setItem("TrackRecord_Queue_loginSubmitBack", path);
                    },
                    clear: function () {
                        window.localStorage.removeItem("TrackRecord_Queue_loginSubmitBack");
                    }
                }
            };
            d.changeCallback = function (keyCtrl, path, recount, needlogin, islogged) {//recount:重新记录  needlogin：是否需要登录  islogged：当前是否登录
                if (keyCtrl === undefined || path === undefined) {
                    return;
                }
                if (recount) {
                    d.mylocalStorage.backQueue.clear();
                    d.mylocalStorage.loginSubmit.clear();
                }
                if (needlogin && !islogged) {//需要登录，但是没有登录的情况下
                    d.mylocalStorage.loginSubmit.set(path);
                }
                var arr = d.mylocalStorage.backQueue.get();
                d.mylocalStorage.backQueue.set(arr, keyCtrl, path);


                //var _____path = d.mylocalStorage.backQueue.get();
                //alert("记录完成后的路径：" + _____path);
            }

            d.back = function ($location) {
                var _path = d.mylocalStorage.backQueue.removeLast();
                //alert("返回后移除的值：" + _path)
                if (sytdapp.platform.isValid()) {//true :是移动平台
                    if (_path === "/") {
                        AppConfigModel.doGoPageApp();
                    } else {
                        $location.path(_path);
                    }
                } else {
                    $location.path(_path);
                }

            }
            d.submitBack = function ($location) {
                var path = d.mylocalStorage.loginSubmit.get();
                if (path != undefined) {
                    d.mylocalStorage.loginSubmit.clear();
                    $location.path(path);
                }
                else {
                    d.back($location)
                }
            }
        })(backQueue2);

        var obj = {
        };
        var config = {
        };
        obj.get = function (typename, url, successCallback, options) {
            var _host = sytdapp.APIHOST;

            url = _host + url;
            $http.get(url, config)
                .success(function (data) {
                    successCallback(data);
                })
                .error(function (data, status, headers, config) {
                    errorCallback(data, status, headers, config);
                });
        }
        obj.post = function (typename, url, successCallback, options) {
            //debugger;
            var _host = sytdapp.APIHOST;
            url = _host + url;
            var options = options || {
            };
            var _data = options.data || {
            };
            $http.post(url, _data)
                .success(function (data) {
                    successCallback(data);
                })
                .error(function (data, status, headers, config) {
                    errorCallback(data, status, headers, config);
                });
        }

        //obj.backQueueChangeCallback = backQueue2.changeCallback; 
        //backQueue.changeCallback;
        obj.trackRecord = {
            record: backQueue2.changeCallback,
            back: backQueue2.back,
            sunbmit: backQueue2.submitBack
        };
        obj.redirect2login = function () {
            if (sytdapp.platform.isValid()) {//平台无效
                AppConfigModel.doGoPageApp("#/login");
            } else {
                $location.path("/login");
            }
        }
        obj.redirect2Index = function () {
            if (sytdapp.platform.isValid()) {//平台无效
                AppConfigModel.doGoPageApp("#/");
            } else {
                $location.path("/");
            }
        }
        obj.redirect2Center = function () {
            if (sytdapp.platform.isValid()) {//平台无效
                AppConfigModel.doGoPageApp("#/center");//
            } else {
                $location.path("/center");
            }
        }


        obj.deviceready = function (title, fn) {
            if (sytdapp.platform.isValid()) {//平台无效
                document.addEventListener("deviceready", function () {
                    MessageApp.takeTitle(title);
                    fn();
                });
            } else {
                fn()
            }
        }


        obj.accessStatistics = function (pageMark) {//页面访问两统计
            var _data = {
                CustomerId: sytdapp.LoggedUser.get(),
                PageMark: pageMark,
            };
            obj.post("页面访问量统计",
                "AccessStatistics/call",
                function () { },
                {
                    data: _data
                })
        }

        obj.native_search = function (fn) {//导航按钮事件
            if (sytdapp.platform.isValid()) {//平台无效
                window.zjwapp = window.zjwapp || {};
                window.zjwapp.native_search = fn;
            }
        };

        obj.redirectTo = function (path) {
            $location.path(path);
        }

        return obj;
    }
]);
